Roll up information for Year To Date

Hello,
I have some sales data as follows
Item_Id Country_Id Region_ID Month_begin_date Quantity Amount
s1 C1 r1 10/1/2008 20 2000.05
s2 C1 r1 10/1/2008 100 4350.45
s3 c2 r2 11/1/2008 50 3200.00
s3 c1 r3 12/1/2008 102 5102.50
s3 C2 r2 01/1/2009 35 1989.45
s2 c1 r1 02/1/2009 56 2989.00
s3 C3 r3 03/1/2009 29 1129.00
s1 c3 r3 04/1/2009 455 3000.00
s2 c2 r2 05/1/2009 123 2345.00
s3 c2 r1 06/1/2009 40 1878.00
s1 c2 r2 07/1/2009 65 1123.00
s2 c2 r2 08/1/2009 100 1000.50
s3 c3 c3 09/1/2009 191 2500.00
s1 c2 r3 08/1/2009 299 3448.50
s2 c3 r3 09/1/2009 432 5000.00
s3 c1 r3 07/1/2009 175 4000.00
here item_id,country_id,region_id,month_begin_date are together composite primary key...
I want to get year to date (sum from the INITIAL date to sysdate) OF sum of quantity and sum of amounts to above data .
I.E. Query should consider records until 7/1/2009
and calculates sum of quntity and amount group by primary key fields...
s1 C1 r1 10/1/2008 20 2000.05
s2 C1 r1 10/1/2008 100 4350.45
s3 c2 r2 11/1/2008 50 3200.00
s3 c1 r3 12/1/2008 102 5102.50
s3 C2 r2 01/1/2009 35 1989.45
s2 c1 r1 02/1/2009 56 2989.00
s3 C3 r3 03/1/2009 29 1129.00
s1 c3 r3 04/1/2009 455 3000.00
s2 c2 r2 05/1/2009 123 2345.00
s3 c2 r1 06/1/2009 40 1878.00
s1 c2 r2 07/1/2009 65 1123.00
Thanks in advance...
please help me out....

Welcome to Forum!!
SELECT
Item_Id, Country_Id, Region_ID, Month_begin_date, SUM(Quantity) , SUM (Amount)
FROM TABLE_NAME  --Add your table Name
WHERE Month_begin_date < = SYSDATE  --will Reject records having date > sysdate
                                    --Remember the date comparision is bit tricky
GROUP BY Item_Id, Country_Id, Region_ID, Month_begin_date1 min :: You want to GROUP the data on the basis of primary key: thats NOT logical
Edited by: AJ99 on Jul 1, 2009 11:25 AM
Edited by: AJ99 on Jul 1, 2009 11:29 AM

Similar Messages

  • GROUP BY GROUPING SETS for a selected month and for year to date

    Below is a code example to demonstrate this question:
    declare @test table (ID int, Quantity int, Day date);
    insert into @test values
    (4, 500, '1/18/2014'),
    (4, 550, '1/28/2014'),
    (7, 600, '1/10/2014'),
    (7, 750, '1/11/2014'),
    (7, 800, '1/20/2014'),
    (1, 100, '1/2/2014'),
    (1, 125, '1/10/2014'),
    (8, 300, '1/7/2014'),
    (9, 200, '1/17/2014'),
    (9, 100, '1/22/2014'),
    (4, 900, '2/18/2014'),
    (4, 550, '2/28/2014'),
    (7, 600, '2/10/2014'),
    (7, 700, '2/11/2014'),
    (7, 800, '2/20/2014'),
    (1, 100, '2/2/2014'),
    (1, 150, '2/10/2014'),
    (8, 300, '2/7/2014'),
    (9, 200, '2/17/2014'),
    (9, 100, '2/22/2014'),
    (4, 500, '3/18/2014'),
    (4, 550, '3/28/2014'),
    (7, 600, '3/10/2014'),
    (7, 750, '3/11/2014'),
    (7, 800, '3/20/2014'),
    (1, 100, '3/2/2014'),
    (1, 325, '3/10/2014'),
    (8, 300, '3/7/2014'),
    (9, 200, '3/17/2014'),
    (9, 100, '3/22/2014'),
    (4, 500, '4/18/2014'),
    (4, 550, '4/28/2014'),
    (7, 100, '4/10/2014'),
    (7, 750, '4/11/2014'),
    (7, 800, '4/20/2014'),
    (1, 100, '4/2/2014'),
    (1, 325, '4/10/2014'),
    (8, 300, '4/7/2014'),
    (9, 200, '4/17/2014'),
    (9, 100, '4/22/2014'),
    (4, 500, '5/18/2014'),
    (4, 550, '5/28/2014'),
    (7, 600, '5/10/2014'),
    (7, 750, '5/11/2014'),
    (7, 50, '5/20/2014'),
    (1, 100, '5/2/2014'),
    (1, 325, '5/10/2014'),
    (8, 300, '5/7/2014'),
    (9, 200, '5/17/2014'),
    (9, 100, '5/22/2014');
    --detail
    select *
    from @test;
    --aggregation
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    go
    This is the aggregation query result:
    However, the desired result is to return only two rows: one row for month 3 and the other row for year to date (in the picture above YTD is the row that appears with {null} in the Month column).  Is there a way to achieve this goal by modifying the
    sample code above?  The requirement is to only read the data once (do not want a solution that involves a UNION which implies reading the data twice).

    you can add required filters in having clause. Here is the query -
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    having
    month(Day) = 3 or month(Day) is null;

  • Using an expression in SSRS to display rolling 12 month and year to date volumes

    I need some help in writing an expression in SSRS. I have a table that contains date columns and rows that contain different types of data groups. (e.g. total number of items received during the month, total dollars for the month, etc.) I want to add two
    new columns to the end of the report that will display a rolling twelve month total for each of the different rows of data. Plus a column that would show year to date totals for the same rows.
    I was thinking I could accomplish this by adding expressions for each row in the new 'rolling twelve month' and 'YTD' columns in my report however, I'm not sure how to structure the expressions to achieve this.
    Here is an example of how my report currently looks. (I added a pipe delimeter in case the formatting changes once this is submitted.)
                             Jan-2014 | Feb-2014 | Mar-2014 | Apr-2014 | Rolling 12 mth | YTD
    Items received     100 | 35 | 45 | 12 | 192 | 192
    Dollars                $50.00 | $25.00 | $120.00 | $15.00 | $210.00 | $210.00
    Any guidance you can provide would be appreciated.
    Thank you  

    This example shows how to get what you need. It'll take modifying your query to add two cased columns onto the end.
    DECLARE @forumTable TABLE (periodYear INT, periodMonth INT, periodMonthName VARCHAR(12), periodDollars MONEY, periodItems INT)
    DECLARE @i INT = 0
    SET NOCOUNT ON
    WHILE @i < 24
    BEGIN
    INSERT INTO @forumTable (periodYear, periodMonth, periodMonthName, periodDollars, periodItems)
    VALUES (YEAR(DATEADD(MONTH,-@i,GETDATE())), Month(DATEADD(MONTH,-@i,GETDATE())), DATENAME(MONTH,DATEADD(MONTH,-@i,GETDATE())), 1000-@i, 100-@i)
    SET @i = @i+1
    END
    SET NOCOUNT OFF
    SELECT *,
    CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodItems ELSE 0 END AS ytdItems,
    CASE WHEN CONVERT(VARCHAR,periodYear) + '-' + CONVERT(VARCHAR,periodMonth) + '-01' > DATEADD(MONTH,-12,GETDATE()) THEN periodDollars ELSE 0 END AS ytdDollars
    FROM @forumTable

  • Table for Year to date payments made to vendors

    Hi friends,
    I am generating one query, in which I have to show year to date payments made to vendors.
    can anyone tell me from which table and from which foield can I get this information.
    Please help.

    hi,
    GO to SE16 and select doc type wise , you will get a solution .
    i hope it helps you.
    regds,
    raman

  • A query to create sales information for a specific date.

    Hi,
    Please look at attached image, you will see how this query look like. This query will generate all sales from 1/1/2014 until today. I would like to see if the query can create the sales report for a range from 1/1/2014 until yesterday (does not included any sales for today). Any help will be appreciated.
    -Bill

    Hi Bill,
    The query attached looks like it is selecting results based on the salesorder name starting with the current year. As is written, it won't be able to filter out today.
    If you want to exclude today, you'll need to modify the current selectivity predicate for today to perhaps a BETWEEN predicate ( e.g. table.datefield BETWEEN '2014-01-01' and DATEADD(day,-1,GETDATE()) ) or add an exclusion predicate ( e.g. table.datefield <> DATEADD(day,-1,GETDATE()) ).
    Note that you'll need to have a field in the data that has the day. Your query does not have any schema information, and all it seemingly reveals is that a salesorder name starts with the current year.
    Hope this helps,
    Tyson

  • Seeing average minutes for year to date

    I would like to check and see how many minutes are used on average per month for the last year - is there anyway to do that online?

    Manually, yes.   Pull up each of your bills for the last year, find the total minutes, figure the average.
    A stat you can click and get easily?  I don't think so.

  • Year to Date using SAP variables

    I've run into a sticking point when trying to create a year to date calculation that works without user entry. The infocube is updated by finance each month (for the previous month) after the final adjustments are made. For this reason, when the query pulls YTD information, it should be cumulating from January 20XX to Current Month - 1.
    The first way that I tried was to use overlapping restrictions: Fiscal Year/Period < Current Fiscal Year/Period AND Fiscal Year = Current Fiscal Year. This worked very well until we reached January. Now the overlapping restrictions return no results since all previous months are not in the current fiscal year.
    I've also attempted using the SAP exit variable 0FYTLFP (Cumulated to Last Fiscal year Period) on Fiscal Year/Period. It is not working, and I assume it is because the last fiscal year period is falling into a different fiscal year. Using it today, the value I get is equal to the value for Jan 2007. The variable seems to first look up the first day of the current fiscal year, saves that as one end of the range, then goes to the previous month to get the other end of the range. I tried offsetting this variable by -1 and the value returned was equal to Dec 2006, but not YTD.
    I'm assuming it must be possible to use the standard SAP delivered objects to create a working YTD calculation that does not require manual entry and cumulates correctly through current period - 1. Does anyone have any suggestions?
    Thanks!

    Dear Adam,
    For Year to Date , We have created a Customer Exit , For working , Create a Variable for 0calday and populate that with from and to value ...to value would be Sy-datum and From value is year starting date. Hope it helps..
    Thanks,
    Krish

  • Function module for year todate

    Hi ,
    Here i am looking for a functiona module for year to date (YTD ) .
    For example fiscal year is Apr 2010 to till date we need to have the information . to get this kindly suggest the FM .
    Thanks
    Venkat

    Hi
    Please take some pain in searching on Forum.
    However have a look at this link but make sure you search for available information on SCN for all your future basic queries.
    [http://wiki.sdn.sap.com/wiki/display/ABAP/FunctionModulerelatedonDate+calculations]
    Regards
    Abhii

  • Year to Date and Monthly totals

    I know that this is rather simplistic, but I'm new to Discoverer and need to set up a bunch of sales reports with MTD and YTD columns. I'm going to be using the same SQL query for many of my reports but customizing the reports to show sales by state, product line, etc.
    Is there a formula/function I can use in Discover for the Month to Date and Year to Date totals?
    Thanks,
    Joseph

    Hi Joseph
    You can use the analytic range SUM calculation for these. For the month to date, use the a PARTITION BY of month with a range of all the preceding rows in the partition up to and including the current row. For the year, you would simply change the PARTITION BY to be the year.
    Here are some examples drawn from my own database:
    I have the following items:
    ORDER_YEAR
    ORDER_MONTH
    ORDER_DATE
    SELLING_PRICE
    With these defined, the formula for month to date is:
    SUM(Sales.Selling Price SUM) OVER (PARTITION BY ORDER_MONTH ORDER BY ORDER_DATE ASC ROWS UNBOUNDED PRECEDING)
    The formlua for year to date is:
    SUM(Selling Price SUM) OVER(PARTITION BY ORDER_YEAR  ORDER BY  ORDER_DATE ASC  ROWS  UNBOUNDED PRECEDING )
    Basically what we are doing is telling Discoverer to SUM the SELLING_PRICE, and you should be able to take these and adjust them for your own report.
    Let me take a look at the month to end and describe what is going on. Basically the PARTITION BY is defining a set of rows which are to be included. In this case it is all rows that have the same ORDER_MONTH. The ORDER BY clause tells Discoverer to place the items in order, with the oldest order first. The ROWS UNBOUNDED PRECEDING tells Discoverer to SUM all of the items within the set (within the PARTITION BY) from the oldest item (UNBOUNDED PRECEDING) to and including the current item. We could have added a BETWEEN clause too but that is implied. With a BETWEEN clause it would look like this:
    SUM(Sales.Selling Price SUM) OVER (PARTITION BY ORDER_MONTH ORDER BY ORDER_DATE ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
    If you want the current row to be included with UNBOUNDED PRECEDING you don't need to explicitly name it because that is the default. Other options you could use are these:
    UNBOUNDED FOLLOWING - this SUMS to the end of the PARTITION
    ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - you can guess that this will add all of the items, which you will rarely use because if you omit the ROWS command then this range between first and last is actually the default
    Rather than ROWS BETWEEN you can also say RANGE BETWEEN, like this:
    SUM(Sales.Selling Price SUM) OVER (PARTITION BY ORDER_MONTH ORDER BY ORDER_DATE ASC RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
    I hope this little dissertation on running totals helps.
    Best wishes
    Michael

  • "Dependecies" tab doesn't show any information for a selected table version 4.0

    Hello,
    I work with SQL Developer 4.0.0.13. I can see 20 tables in the list. When I select one table, in the tabs on the right side I can see information for "columns" and "data" and "constraints" and "indexes"... but the tab "Dependencies" doesn't show any information about references between this table and other tables in the schema.
    Oracle database is v11.2
    Can you please tell me what do I need to do in order to see information on "Dependencies" tab for a table?
    Thank you,
    Milan

    Hi, here is my example of XML extension showing referencing tables:
    Save the following XML to a file.
    <items>
      <item type="editor" objectType="TABLE">
        <title><![CDATA[*Referencing Tables]]></title>
          <query>
            <sql><![CDATA[SELECT
      cfk.owner "OWNER",
      cfk.table_name "TABLE NAME",
      cols.column_name "COLUMN",
      cfk.constraint_name "CONSTRAINT NAME",
      cfk.delete_rule "DELETE RULE",
      'SQLDEV:LINK:' || cfk.owner || ':TABLE:' || cfk.table_name ||
      ':oracle.dbtools.raptor.controls.grid.DefaultDrillLink' "LINK"
    FROM
      sys.all_constraints cpk,
      sys.all_constraints cfk,
      sys.all_cons_columns cols
    WHERE
      cpk.owner = :OBJECT_OWNER AND
      cpk.table_name = :OBJECT_NAME AND
      SUBSTR(cpk.table_name, 1, 4) != 'BIN$' AND
      SUBSTR(cpk.table_name, 1, 3) != 'DR$' AND
      cpk.constraint_type in ('P', 'U') AND
      cfk.r_owner = cpk.owner AND
      cfk.r_constraint_name = cpk.constraint_name AND
      cfk.constraint_type = 'R' AND
      cols.owner = cfk.owner AND
      cols.constraint_name = cfk.constraint_name
    ORDER BY
      cfk.owner, cfk.table_name, cfk.constraint_name,
      cols.column_name]]>
          </sql>
        </query>
      </item>
    </items>
    In SQLDeveloper select Preferences -> Database -> User Defined Extensions and click <Add Row>.
    In the "Type" field enter "EDITOR" and in the "Location" field enter the path to the file with XML.
    After restarting SQLDeveloper You should see a new tab "*Referencing Tables" for tables.

  • Year to Date reports using Prompts

    Hi.
    I'm trying to build a report that will show results of sales compared to Annual targets. All those fields are fields directly at the opportunity level (amount and targets). I also need to put a prompt to select dates from and to, for the Opportunity Close date. I've used Variables for this, and am comparing throuhg two filters "Opportunity.Close Date greater than pvCloseDateFrom" and "Opportunity.Close Date lower than pvCloseDateTo". I'm also presenting the % Achievment, which is the % of Total Sales compared to the Target field.
    So far the report is simple
    User - Total Amount of Sales - Target FIeld - % Realized.
    The difficulty I'm facing concern the next set of columns in the report : I also need to present the Year to Date Target that is represented by the number of days between the two dates prompted (for instance if I prompt 01/01/2010 and 31/03/2010 needs to show 25% of the total target) along with the % of SAles compared to this new target calculated field.
    I'm having issues with the TIMESTAMPDIFF function through the Presentation Variables as it either tells that the type is not correct even if I'm trying to use the CAST function or it discard part of the string when I'm trying to rebuilt the date as a timestamp : in my configuration date are presented D/M/YYYY where my timestamp function expects DDDD-MM-DD HH-MI-SS.
    Is there anyone who could have an example of such calculations in a report based on dates and duration ?
    Thanks in advance for your help !!
    Olivier

    Dear Adam,
    For Year to Date , We have created a Customer Exit , For working , Create a Variable for 0calday and populate that with from and to value ...to value would be Sy-datum and From value is year starting date. Hope it helps..
    Thanks,
    Krish

  • Need template with daily entries, & monthly sums & year-to-date sums

    I'm trying to find a budget template for Numbers -- adapted from the checkbook template, maybe? --
    where one can enter daily transactions (with category) in 12 different monthly tables, show each month's category sums in tables next to the daily ones,
    and also have a table for Year-to-Date category sums, probably at the top of the whole thing.
    In other words, each individual transaction would have to be added to its monthly category table, AND to the Year-to-Date category table.
    Has anyone done this?  Can it be done in Numbers?
    Thanks.

    Hi Jackie,
    That makes more sense than my original reading. The function you are looking for is "SUMIFS."
    Here's an example, with the transactions recorded in the "Data" table, and the January sums reported in the "Summary" table.
    "Data" contains no formulas.
    On "Summary":
    A1 contains the start date, Jan 1, 2012.
    The rest of column A contains the category names, which must exactly match the names used in the Data table.
    B2 contains the formula, which is filled down the rest of column B:
    Summary::B2: =SUMIFS(Data::$C,Data::$B,"="&A,Data::A,">="&$A$1,Data::$A,"<="&EOMONTH($A$1,0) )
    For an amount to be included in the SUM, three conditions must be met:
    -- The transaction category must match the category in that row of Summary.
    -- The transaction date must be on or after the date in A1 of Summary
    -- The transaction date must be on or before the last day of the month in A1 of Summary.
    Regards,
    Barry

  • How to load member for "sales same date last year"?

    I need to load a member in Measures named "PriorYrSales" with "Sales" for the same date last year as today's date. Thus, retrieving "PriorYrSales" for 2/10/2002 would return the sales amount for 2/10/2001. Since days roll-up to months, quarters, years, it would be easy to determine how we're doing compared to the same time last year.Data is loaded each day for a date range from the current date and the preceding x days. Substitution variables are available for the beginning and ending date and the same dates for last year.For example: Data is loaded from beginning date of 2/01/2002 through ending date of 2/10/2002.The prior year date variables contain 2/01/2001 and 2/10/2001.The time period dimension is as follows:FY01->Jan2001-->01012001 (Alias: 1/01/2001)-->01022001 (Alias: 1/02/2001)-->all the dates in Jan->Feb2001-->02012001 (Alias: 2/01/2001)-->02022001 (Alias: 2/02/2001)-->all the dates in Febetc.FY02->Jan2002-->01012002 (Alias: 1/01/2002)-->01022002 (Alias: 1/02/2002)-->all the dates in Jan->Feb2002-->02012002 (Alias: 2/01/2002) -->02022002 (Alias: 2/01/2002)-->all the dates in Febetc.Thanks your any and all suggestions.Phil

    Perhaps I wasn't clear in the first post. The intent is to easily compare sales for a current date/period to the same date/period last year. Neither Excel nor Analyzer provide a method that I'm aware of to retrieve data as follows:-------------------------------------Period Sales PriorYrSales Diff4/15/2002 1,000 900 100-------------------------------------(900 is sales for 4/15/2001)(100 is the calculated difference.)Nor can I do this:-------------------------------------Period Sales Period Sales Diff4/15/2002 1,000 4/15/2001 900 100-------------------------------------What Excel and Analyzer do allow is:-------------------------------------Period Sales 4/15/2002 1,0004/15/2001 900-------------------------------------I readily acknowledge that the data is redundant but I can't think of another option that will allow Excel and Analyzer to easily retrieve the values for comparison. If the PriorYrSales member can be loaded then the users can compare years, quarters, months and days quite easily.My challenge is knowing how use a calc script to derive prior year dates that correspond to current year dates. Something like:PriorYrSales->04152002 = Sales->04152001I've considered arrays but I've never used them and the documentation is not helpful enough for me.Thanks for your response.Phil

  • 3 people have been using the same Apple ID for years.  How do we separate the information and create our own Apple IDs?

    Brand new to the community.    I'm confused as to how all of this works, but since we're using the same Apple ID, we seem to be getting eachother's information synced to our phones including contacts, music, etc.  I'd like to separate our accounts, but how do we retain the appropriate information for each individual?

    On person can keep the current account and the other two can migrate their devices to new accounts.  To migrate a device to a new accoun, start by saving any photo stream photos that you want to keep to your camera roll (unless already there) by opening your my photo stream album, tapping Select, tapping the photos, tap the share icon (box with upward facing arrow), then tapping Save to Camera Roll.  If you are syncing notes with iCloud that you want to keep, you'll need to open each of your notes and email them to yourself so you can later copy and paste the text into new notes created in your new account.  Then go to Settings>iCloud, tap Delete Account (which only deletes it from this device, not from iCloud; the person keeping the current account will not be effected by this), provide the password to turn off Find My iDevice and choose Keep on My iDevice when prompted .  Then sign back in with a different Apple ID to create your new account and choose Merge to upload your data.  If the same person has other devices to migrate to this new account, on the other devices they can save the photo stream photos to the camera roll, delete the iCloud account, choose Delete from My iDevice (since the data is already in the new account), the sign into the new account.
    Once you are all on separate accounts, you can go to icloud.com and delete any data that you don't want in your accounts (such as other people's contacts).
    If you're getting each other's music it may be because you have automatic download turned on, which automatically downloads purchases made any other device signed into the same iTunes ID.  To prevent this, go to Settings>iTunes & App Store and turn Music off under Automatic Downloads.

  • Year to date, rolling quarter measures

    I need to implement reports with year to date, rolling quarter (current month + 2 previous month) measures, etc...
    The BO universe is connected to a bex query on a SAP multi provider
    Where do you recommend to implement such measures?
    Should we precalculate them in a SAP BI keyfigure ?
    Should we create a restricted key figures in the bex query and using SAP variable with customer exits to implement for example the rolling quarter functionnality?
    Should be we create a new measure in the BO universe?
    Should we create a new variable in the report. In this case what is the impact on the performance?
    We have about 30.000 records in our cube for about 3 years of data. the volume will grow on a monthly basis but analysis will mainly be done on maximum three years of data.

    Hi,
    this is not related to performance. this is related to the simple fact that the MDX on SAP BW does not have support for something like a Today() or a Now(), which means you can't have rolling months based on the system date.
    if you use an EXIT variable you have the keyfigures in the universe and can leverage it in the Web Intelligence report.
    ingo

Maybe you are looking for