Calculations from report data

Hi,
I have been using the below SQL in one of my reports to show Sales data. It has recently come to my attention that calculating the likes of Fin Year and Fin Period are best done at the presentation section of the report rather than in the SQL. Is this correct?
If so how would I script the function to calculate these?
Cheers
Paul

Sorry, I forgot to add it. Here you go:
--DECLARE @FINANCIALYEAR VARCHAR(4)
--DECLARE @FINPERIOD VARCHAR(4)
--SET @FINANCIALYEAR = '2013'
--SET @FINPERIOD = '10'
SELECT
CASE
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2
THEN YEAR(dbo.SALESTABLE.CREATEDDATE) - 1
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4
THEN YEAR(dbo.SALESTABLE.CREATEDDATE)
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 AND YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011
THEN YEAR(dbo.SALESTABLE.CREATEDDATE)
ELSE YEAR(dbo.SALESTABLE.CREATEDDATE) - 1
END AS [Fin Year],
CASE
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 10
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 3
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 2
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) = 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) = 3
THEN 13
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2013 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 3
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 9
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 3
END AS [Period],
dbo.SALESTABLE.SALESID AS [Sales ID],
CONVERT(DECIMAL(12, 2), SUM(dbo.SALESLINE.LINEAMOUNT)) AS [Value],
dbo.SALESTABLE.SALESNAME AS [Name]
FROM dbo.SALESTABLE
INNER JOIN dbo.SALESLINE ON dbo.SALESTABLE.SALESID = dbo.SALESLINE.SALESID
WHERE (
CASE
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2
THEN YEAR(dbo.SALESTABLE.CREATEDDATE) - 1
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4
THEN YEAR(dbo.SALESTABLE.CREATEDDATE)
WHEN MONTH(dbo.SALESTABLE.CREATEDDATE) = 3 AND YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011
THEN YEAR(dbo.SALESTABLE.CREATEDDATE)
ELSE YEAR(dbo.SALESTABLE.CREATEDDATE) - 1 END) IN (@FINANCIALYEAR)
AND
(CASE
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 2
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 10
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) <= 2011 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 3
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 2
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) = 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) = 3
THEN 13
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2013 AND MONTH(dbo.SALESTABLE.CREATEDDATE) <= 3
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) + 9
WHEN YEAR(dbo.SALESTABLE.CREATEDDATE) >= 2012 AND MONTH(dbo.SALESTABLE.CREATEDDATE) >= 4
THEN MONTH(dbo.SALESTABLE.CREATEDDATE) - 3
END) IN (@FINPERIOD)
AND GBORDER = '1'
AND SALESTABLE.SALESTYPE = '3'
GROUP BY MONTH(dbo.SALESTABLE.CREATEDDATE), YEAR(dbo.SALESTABLE.CREATEDDATE), dbo.SALESTABLE.SALESID, dbo.SALESTABLE.SALESNAME
ORDER BY 1, 2 ASC
So I'd be better working it out this way anyway?

Similar Messages

  • Time calculation from one date to some other date

    Hello,
    I want to time calcualtion from one date to other date period.
    for calculating total hr's from one date to other date.plz let me know the logic.
                           Date                      Time
    Eq:  1st date:   22.05.2008             01.10.00
          2nd date:   25.05.2008             12.10.00
    I want the total hrs from 22.05 to 25.05 like i need result as
    from 22 to 25 total hrs based on the time given.

    Hello,
    Instead of FM..We can achieve by the following program...
    REPORT YRT_TEST1.
    parameters : date1 like sy-datum,
    date2 like sy-datum.
    data: days(3) type n.
    data: years(10) type p decimals 3.
    start-of-selection.
    days = date2 - date1.
    years = days / 365.
    write: / days,
    years.
    Now Multiply 24  to days to get hours and the multiply with 60*60 to get the seconds
    ***************Reward points,if found useful

  • Condition Type for item calculated from delivery date

    Dear Experts,
    We need that the condition type MWST for PO item will be calculated from Item delivery date ,
    But we see that always in Analysis pricing the efected date is PO date and not item delivery date .
    Please advise how we should configure the condition ?
    Thanks,
    Moshe

    Hi,
    In standard configuration you cannot set item delivery date as a pricing data.
    Maybe you shoud look at SAP enchancement - in dedicated structures you can pass additional item data (structure KOKMP).
    IMG link:
    Materials Management -> Purchasing -> Conditions -> Define Price Determination Process -> System Enhancements
    hope it helps.
    regards,
    wojciech

  • Weeks calculation from the date

    Hi BW mates,
    I am currently working on SCM Queries. I have a report where I have to display the sales for 16 weeks from the date of release of cinema.
    For eg.
    In rows, Title and Release date are displayed in rows. In columns data is displayed with Wee1, Week2,,,,,,,,,up to Week 16.
    Generally using Off sets we can achieve using current week. But here I have to consider the release date. The release date is nothing but the equals to current week from there it has to show all 16 weeks invidually
    <b>Title</b>                     <u>Week1 Weekk2 Week3 Week4</u>
    <b>Release date</b>
    <b>Actual Sales</b>
    <b>Target sales</b>
    Please suggest me how to do this.
    Thanks,
    Sudhakar.

    hi,
    you can use use a flag in the update rule with 16 values e.g. A,B,C.....L for 16 weeks. pupulate the flag based on the release date.There is a function module which convert date to week. Once this is done create a restricted Key figure in BEx restricting the sales based on the flag i.e A for WEEK1, B for WEEK2.
    Hope this helps.

  • SSAS data source calculating from two data source

    Hi There,
    I have SSAS cube and use SSRS 2008R2. Basically I have cube A for current month income statement, cube B from previous month, they have shared the same dimensions. I want to create  report to show
                      current month  previous Month            Calculation
       Account               Amount A         Amount B            Amount A - Amount
    B
    Revenue                 Amount A         Amount B            Amount B
       Expense              ,,,,,,
    Net Income
    Any advice?
    Thanks
    Don

    Hi Dz0001,
    According to your description, you want to combine the data from two cube into one tablix. Right?
    In this scenario, since your two cube share same dimensions, we can use lookup() function to retrieve the income from another dataset based on the data field for dimension rows.
    For example, let's say you have DataSet1 retrieves data from cube A with data fields
    Account and Income, DataSet2 retrieves data from cube B with data fields
    Account and PreIncome. When rendering the data field from DataSet1 in a table, you can use the expression below in detail row.
    =Lookup(Fields!Account.Value,Fields!Account.Value,Fields!PreIncome.Value,"DataSet2")
    Reference:
    Lookup Function (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou
    TechNet Community Support

  • Calling stored procedure from Reports Data wizard

    What is the exact syntax for entering a stored proc name in the Data wizard, I have created a TEST stored proc which all it does is a simple select statment but the Data wizard complaints that WRONG # of parameter when in fact TEST does NOT take any params. Any ideas?

    I am using Reports 9i & use JDBS query. When it gets to the section that says enter SQL or Stored proc, I enter a simple TEST proc which takes no params & get error msg as explained before ... I don't see any info in the Reports manual as to how to call a proc ... where would I find that info?
    Thx.

  • Interest calculation from invoice date

    Hi Friend
    Customer invoice date : 01.08.2014
    Due date is (20 day's)  : 20.08.2014
    Customer make payment on 25.08.2014,
    if we calculate interest in sap count the 5 Day's (21.08.2014 to 25.08.2014)
    but client is requirement is interest calculation on 25 days (01.08.2014 to 25.08.2014). any standard setting is there are customization are required....?
    Regrd"s
    Mallesh

    Hello Mallesh,
    You need to review your payment terms which are assigned in the Customer/vendor master data.
    regards
    Ray

  • Due date calculation from GR Date / Service entry sheet date

    Dear Friends,
    GRN Date--01.05.2009
    Payment terms--- Within 45 days due net
    Transaction code---FBL1N
    System should not output these records before 14.06.2009 in FBL1N.
    It should ouput on or after 14.06.2009.
    Regards
    R Panda
    Edited by: Rutabhadra Panda on Jun 2, 2009 9:18 AM

    Hi
    Try with payment terms option
    SPRO- SAP IMG- Material Management - Purchasing - Vendor Master - Define terms of payment
    regards,
    Raman

  • Link from Report to Form in a Page

    1. I have created a page in the Page Groups. I have five tabs on this page. Under a tab I have one Report added as a Portlet. This Report has a LINK to a From. When I click on the LINK the Form opens, but not in the Portlet area. Is it possible to have a Form open in the Portlet area (replacing the Report)?
    2. I get the following error when trying to add one particular Report as a Portlet in a page:
    An unexpected error has occurred in pages: wwpob_api_page.add_portlet (WWC-44847)
    An unexpected error has occurred in portlet instances: wwpob_api_portlet_inst.create_inst (WWC-44846)
    Do anyone have any ideas?

    Doug wrote:
    I am using version 4.0 of APEX.  My question concerns linking to other APEX pages from a report.  In APEX we link to another page, which may be a form or another report, by using a column in the report as a link column.  Any column may be used to transfer values from any other column.  This works fine, but the disadvantage is that whichever column is used as the link column has a heading which identifies the column's purpose but may not identify the purpose of the transition to another page.  In Oracle Forms, we could use buttons as a column of the multi-row screen (i.e. same as APEX report), and the button's label identified the purpose for the transition.
    Is there any way to create a column in an APEX report  to serve the same purpose as the button in Oracle Forms?
    When discussing "reports" it is essential to indicate whether this means a standard report or an interactive report in order to receive an appropriate response.
    It is possible to create a link column that is distinct from report data columns. In standard reports, this is done using the Add Column Link option from the Tasks menu in the right sidebar of the Report Attributes page. In interactive reports, define a Link Column on the Report Attributes page.
    To provide further information about links to users in both cases, specify an HTML title attribute for the link in the Link Attributes property of the link definition. This will be rendered as a tooltip when the cursor hovers over the link in visual browsers, and as an audio cue on navigation to the link when using a screen reader.

  • Substitution for Tax reporting date

    Hi,
    I have created a substitution at document header level to change Tax Reporting date field.
    It works correctly when I enter a fixed value or another field value, but when I enter a user exit it does not work in VF11 transaction
    Which could be the problem?
    Thanks

    Dear expert
    Problems calculating tax reporting date in VF11 transaction
    user exit VF11 for accounting
    Regards
      Ajeesh.s

  • Retest Date Calculate from manufacturing Date

    Dear all,
    If we are doing Goods Receipt  for Finished Goods, Semi Finished Goods or Raw Material the  Retest date is calculated from Posting Date (GRN) as per SAP Standard. But our client required it should be the retest date is calculate from Manufacturing Date of Particular Material.
    Please Guide How to Map it , what configuration i want to do in SPRO 
    s. sakthivel

    Hi Shaktivel,
    The same situation we faced in one of my pharma implementation, As per standard,retest date will be calculated from the GR date + retest period in days given in the master.If we want to create from the date of manufacturing date we have to opt for user exits.we done through an user exit during usage decision.
    regards,
    Lenin. A

  • YTD report generated from excel data yielding incorrect results

    I am trying to generate a YTD report from the data present in an excel sheet. However the result is coming out to be incorrect for YTD sales
    The data sheet looks like this.(SaleDate is in *3/14/2009 format).
    SNo     manufacturer     date     # of CarsSold
    1     Hyundai     1/2/2010     10
    2     Maruti     1/2/2010     15
    3     Hyundai     1/14/2010     11
    4     Maruti     1/14/2010     15
    5     Hyundai     2/1/2010     10
    6     Maruti     2/1/2010     13
    My logical layer consists of the following 3 tables
    Manufacturer Dim table with only 1 column 'manufacturer'
    Date dim table with only 1 column 'date'. Additional derived columns in this logical table created for YTD calculations are as follows:
    CALENDER_YEAR_NAME---- EXTRACT( YEAR FROM testdata.TimeDim."date")
    QUARTER_OF_YEAR------- EXTRACT( QUARTER_OF_YEAR FROM testdata.TimeDim."date")
    MONTH_OF_YEAR----------- EXTRACT( MONTH FROM testdata.TimeDim."date")
    CALENDER_QUARTER_DESC------ CONCAT( CAST (testdata.TimeDim.CALENDER_YEAR_NAME AS CHARACTER ( 30 )), CAST (testdata.TimeDim."QUARTER_OF_YEAR" AS CHARACTER ( 30 ))) ////appending year name to month name for uniqueness
    CALENDER_MONTH_DESC------ CONCAT( CAST (testdata.TimeDim.CALENDER_YEAR_NAME AS CHARACTER ( 30 )), CAST (testdata.TimeDim.MONTH_OF_YEAR AS CHARACTER ( 30 )))
    After that time dimension was created with the following levels.
    timedimtotal
    year
    quarter
    month
    timedimdetail-Chronological key has been specified at all levels of the time dimension created for YTD calculation.The key at the lowest detail level was specified as 'date' column. At the upper levels it was CALENDER_MONTH_DESC,CALENDER_QUARTER_DESC,CALENDER_YEAR_NAME etc
    Fact table with 1 column '# cars sold'.The fact table is joined with both the dim tables by complex logical join. Sno has been ommitted and not used in any of the logical tables. Sale YTD column was created in fact table using todate function(year).
    The result am obtaining if i run the report today is:
    CALENDER_YEAR_NAME QUARTER_OF_YEAR MONTH_OF_YEAR # of CarsSold SaleYTD
    2,010 1 1 51 51
    2,010 1 2 23 46
    As you can see YTD for month 2 is coming incorrect it should be 51+23. This is jst test records and the same difference exists even if i run against my actual excel sheet
    I would like to know:
    1. Is it right to run YTD report against excel sheet as I checked for the query beign generated by answers, and its firing a lot of functions like Quarter name and monthname etc which i am not sure are supported by excel for answers.
    2. If i am going fundamentally wrong somewhere in this entire approach as i am new to obiee and chances are i might be missing something important.
    Would highly appreciate your help
    Regards
    Himanshu Hira

    I have another solution and that is to actual discard the result before you get to the report stage.
    You can do this by use of the Override Callback SequenceFilePostResultList and if Skipped then discard the result from ResultList.
    Check out this link.
    Regards
    Ray Farmer

  • Report Builder Wizard and Parameter Creation with values from other data source e.g. data set or views for non-IT users or Business Analysts

    Hi,
    "Report Builder is a report authoring environment for business users who prefer to work in the Microsoft Office environment.
    You work with one report at a time. You can modify a published report directly from a report server. You can quickly build a report by adding items from the Report Part Gallery provided by report designers from your organization." - As mentioned
    on TechNet. 
    I wonder how a non-technical business analyst can use Report Builder 3 to create ad-hoc reports/analysis with list of parameters based on other data sets.
    Do they need to learn TSQL or how to add and link parameter in Report Builder? then How they can add parameter into a report. Not sure what i am missing from whole idea behind Report builder then?
    I have SQL Server 2012 STD and Report Builder 3.0  and want to train non-technical users to create reports as per their need without asking to IT department.
    Everything seems simple and working except parameters with list of values e.g. Sales year List, Sales Month List, Gender etc. etc.
    So how they can configure parameters based on Other data sets?
    Workaround in my mind is to create a report with most of columns and add most frequent parameters based on other data sets and then non-technical user modify that report according to their needs but that way its still restricting users to
    a set of defined reports?
    I want functionality like "Excel Power view parameters" into report builder which is driven from source data and which is only available Excel 2013 onward which most of people don't have yet.
    So how to use Report Builder. Any other thoughts or workaround or guide me the purpose of Report Builder, please let me know. 
    Many thanks and Kind Regards,
    For quick review of new features, try virtual labs: http://msdn.microsoft.com/en-us/aa570323

    Hi Asam,
    If we want to create a parameter depend on another dataset, we can additional create or add the dataset, embedded or shared, that has a query that contains query variables. Then use the option that “Get values from a
    query” to get available values. For more details, please see:http://msdn.microsoft.com/en-us/library/dd283107.aspx
    http://msdn.microsoft.com/en-us/library/dd220464.aspx
    As to the Report Builder features, we can refer to the following articles:http://technet.microsoft.com/en-us/library/hh213578.aspx
    http://technet.microsoft.com/en-us/library/hh965699.aspx
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How Do I Display HTML Formatted Text From A Data Table In Crystal Reports?

    I'm creating reports in Crystal XI.  The information being displayed in the reports comes from data tables where the text is formatted in HTML.
    I've worked with Crystal Reports enough to know that HTML text pulled from a data table doesn't appear in Crystal the same way it does in a web browser.  Crystal Reports ignores all the tags (...unless I'm missing something...) and just displays the text.
    Someone far more Crystal savy than I (...who I don't have access to...) came up with a Formula Field workaround that tricks Crystal Reports into displaying some basic HTML tags.  Here's that workaround:
    <!--
    stringVar TableName := ;
    TableName := Replace (TableName, "<ul>","<br> <br>");
    TableName := Replace (TableName, "<li>", "<br>   &bull; ");
    TableName := Replace (TableName, "</li>", "");
    TableName := Replace (TableName, "</ul>","<br> <br>");
    TableName := Replace (TableName, "<a", "<u><font color='blue'");
    TableName := Replace (TableName, "</a>", "</font></u>");
    TableName
    -->
    QUESTION - Does any similar workaround exist so I can display an HTML Table in Crystal Reports?  If not, is there any way to display HTML formatted text from a data table in Crystal Reports as it would appear in a web browser?

    Hi Steven,
    To display html text in Crystal Reports follows these steps.
    1. Right click on the field and select Paragraph tab.
    2. Under 'Text Interpretation' select 'HTML Text' and click OK.
    I have tried using the way,but it never works.So reply me if there is any way to solve the issue

  • Get the month from a date column with the calculated column

    I am trying to get the month from a date field with the help of calculated column. However I get this syntax error whenever I want to submit the formula:
    Error 
    The formula contains a syntax error or is not supported. 
    the default language of our site is German and [datum, von] is a date field.

    Hi,
    I have created two columns
    Current MM-YY
    Calculated (calculation based on other columns)
    Today
    Date and Time
    Current MM-YY is calculated value with formula as
    =TEXT(Today,"mmmm")
    But the output shows as December instead of May.
    I have tried =TEXT([Datum, von];"mmmm") but no help.
    I am trying to populated the column automatically with current month..ex: if its May the field should show May, next month it should show June an so on.
    Any kind help is grateful.
    Regards,
    Pradeep

Maybe you are looking for