CALCULATE RUNNING TOTALS FOR SUBSETS OF THE DATA IN A SECTION

How can I calculate a running total in BO XI Release 2, (WebI), where my totals only include the value of the current row and the previous 5 rows?
For Example:
        In the data, behind my BO table, I have transaction dates that roll up to a dimension called Period.  The "Period" represents the Year and Month of the transaction date, which is a month's worth of data at a time.  Each month contains an aggregated value that is the Population of items for that month.  The RunningSum function in BO works well, except that I need the running total to only include the current month along with the last 5 months, for a total of 6 months worth of data per row. 
        See my example below.  The Period of JAN 2009 includes the Population for JAN 2009 plus the sum of the Populations from AUG 2008 through DEC 2008 for a total of 6 months worth of data.  FEB 2009 includes SEP 2008 through FEB 2009.  MAR 2009 includes OCT 2008 through MAR 2009...
__________Period_______Population_______6 MOS
__________200801__________54___________54
__________200802__________60__________114
__________200803__________50__________164
__________200804__________61__________225
__________200805__________65__________290
__________200806__________58__________348
__________200807__________70__________364
__________200808__________64__________368
__________200809__________59__________377
__________200810__________62__________378
__________200811__________66__________379
__________200812__________75__________396
__________200901__________62__________388
__________200902__________53__________377
__________200903__________63__________381
__________200904__________67__________386
Six months is obviously no magic number.  I'd like the solution to be flexible enough to use for 3, 12, 18, or 24 month periods as well.

Hi Frank,
can you consider building the rolling sums directly in your database using subselects in the select statement:
eg. select attr1, attr2,key2, (select sum(key1) from B where B.month<=A.month and B.month>=A.month-6) from A
Just create a key figure in your universe and add the subselect statement select sum(key1) from B where B.month<=A.month and B.month>=A.month-6 as select-clause.
ATTENTION: This is SQL pseudo code.
Regards,
Stratos

Similar Messages

  • Filling gaps when calculate running total

    Hello Friends,
    i have a script that calculate running total,but i have gaps between dates.i had some solutions to resolve this issue but it did not perform well.because my source table has over milllion rows.please see my query,output and desired output.
    Thanks in advance.
    IF OBJECT_ID('tempdb..#SalesSummary') IS NOT NULL
    DROP TABLE #SalesSummary
    IF OBJECT_ID('tempdb..#StockDetail') IS NOT NULL
    DROP TABLE #StockDetail
    IF OBJECT_ID('dbo.SalesTransaction') IS NOT NULL
    DROP TABLE SalesTransaction
    IF OBJECT_ID('dbo.DesiredOutput') IS NOT NULL
    DROP TABLE DesiredOutput
    CREATE TABLE [dbo].[SalesTransaction] (
    [StoreKey] [int] NULL
    ,[StockKey] [int] NULL
    ,[OptionKey] [int] NULL
    ,[DateKey] [int] NULL
    ,[Quantity] [int] NULL
    CREATE TABLE [dbo].[DesiredOutput] (
    [Datekey] [int] NULL
    ,[StoreKey] [int] NULL
    ,[StockKey] [int] NULL
    ,[OptionKey] [int] NULL
    ,[SalesFlag] [int] NOT NULL
    ,[Quantity] [int] NULL
    ,[StockQty] [int] NULL
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    1
    ,1
    ,1
    ,20140601
    ,20
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    1
    ,1
    ,1
    ,20140603
    ,- 10
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    1
    ,1
    ,1
    ,20140607
    ,30
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    2
    ,2
    ,2
    ,20140602
    ,15
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    2
    ,2
    ,2
    ,20140603
    ,- 5
    INSERT [dbo].[SalesTransaction] (
    [StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[DateKey]
    ,[Quantity]
    VALUES (
    2
    ,2
    ,2
    ,20140605
    ,20
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140601
    ,1
    ,1
    ,1
    ,1
    ,20
    ,20
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140602
    ,1
    ,1
    ,1
    ,0
    ,0
    ,20
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140603
    ,1
    ,1
    ,1
    ,1
    ,- 10
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140604
    ,1
    ,1
    ,1
    ,0
    ,0
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140605
    ,1
    ,1
    ,1
    ,0
    ,0
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140606
    ,1
    ,1
    ,1
    ,0
    ,0
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140607
    ,1
    ,1
    ,1
    ,1
    ,30
    ,40
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140602
    ,2
    ,2
    ,2
    ,1
    ,15
    ,15
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140603
    ,2
    ,2
    ,2
    ,1
    ,- 5
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140604
    ,2
    ,2
    ,2
    ,0
    ,0
    ,10
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140605
    ,2
    ,2
    ,2
    ,1
    ,20
    ,30
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140606
    ,2
    ,2
    ,2
    ,0
    ,0
    ,30
    INSERT [dbo].[DesiredOutput] (
    [Datekey]
    ,[StoreKey]
    ,[StockKey]
    ,[OptionKey]
    ,[SalesFlag]
    ,[Quantity]
    ,[StockQty]
    VALUES (
    20140607
    ,2
    ,2
    ,2
    ,0
    ,0
    ,30
    SELECT Datekey
    ,StoreKey
    ,StockKey
    ,OptionKey
    ,SUM(Quantity) Quantity
    INTO #SalesSummary
    FROM dbo.SalesTransaction
    GROUP BY Datekey
    ,StoreKey
    ,StockKey
    ,OptionKey
    SELECT Datekey
    ,StoreKey
    ,StockKey
    ,OptionKey
    ,1 AS SalesFlag
    ,Quantity
    ,SUM(Quantity) OVER (
    PARTITION BY StoreKey
    ,StockKey
    ,OptionKey ORDER BY Datekey ROWS UNBOUNDED PRECEDING
    ) AS StockQty
    INTO #StockDetail
    FROM #SalesSummary
    ORDER BY Datekey
    SELECT *
    FROM #StockDetail
    SELECT *
    FROM DesiredOutput

    I am glad that you attempted to post DDL, but you have no idea what you are doing and this is garbage. You have no idea what the ISO-11179 rules are. The meta-data attribute “_key” is never part of a data element name. Never! This is
    how the element is used, and not what it is by its nature. A silly world of only INTEGERs? No keys, no DRI, nothing that can be part of a data model. 
    Why not use an industry standard like GTIN for the items? But I am sure you did not research anything. 
    Why did you have one and only sales transaction? That your table name told us. Most transaction models have an identifier; look at the receipt you got from MacDonald's for the last hamburger you are. 
    Why not use an industry standard like GTIN for the items? But I am sure you did not research anything. 
    Why did you have one and only sales transaction? That your table name told us. Most transaction models have an identifier; look at the receipt you got from MacDonald's for the last hamburger you are. 
    This is a deck of punch cards written in bad SQL. 
    CREATE TABLE Sales_Transactions
    (sale_ticket INTEGER NOT NULL PRIMARY KEY, 
     store_nbr CHAR(10) NOT NULL, 
     gtin INTEGER NOT NULL, --- really CHAR(15)!  
     sale_date DATE NOT NULL, 
     sale_qty INTEGER NOT NULL
      CHECK (sale_qty <> 0));
    I have no idea how you get the unique ticket number for the key, but you can consider CREATE SEQUENCE Sales_Tickets; If you do not know this, Google it. You can build it into the DDL. 
    Did you know that RDBMS does not use Assembly language flags? We also do not use the Sybase “INTO #temp_table” to fake a scratch tape. In fact, you even mount another scratch tape so you can do step-by-step processing! This is not RDBMS. 
    You got the syntax for insertions wrong; you are using the old Sybase stuff. 
    INSERT INTO Sales_Transactions 
    (1, '00001', 1, '2014-06-01', 20), 
    (2, '00001', 1, '2014-06-03', -10), 
    (3, '00001', 1, '2014-06-07', 30), 
    (4, '00002', 2, '2014-06-02', 15), 
    (5, '00002', 2, '2014-06-03', -5), 
    (6, '00002', 2, '2014-06-05', 20);
    It looks like  you want inventory levels as running total
    This is a deck of punch cards written in bad SQL. 
    CREATE TABLE Sales_Transactions
    (sale_ticket INTEGER NOT NULL PRIMARY KEY, 
     store_nbr CHAR(10) NOT NULL, 
     gtin INTEGER NOT NULL, --- really CHAR(15)!  
     sale_date DATE NOT NULL, 
     sale_qty INTEGER NOT NULL
      CHECK (sale_qty <> 0));
    I have no idea how you get the unique ticket number for the key, but you can consider CREATE SEQUENCE Sales_Tickets; If you do not know this, Google it. You can build it into the DDL. 
    Did you know that RDBMS does not use Assembly language flags? We also do not use the Sybase “INTO #temp_table” to fake a scratch tape. In fact, you even mount another scratch tape so you can do step-by-step processing! This is not RDBMS. 
    You got the syntax for insertions wrong; you are using the old Sybase stuff. 
    INSERT INTO Sales_Transactions 
    (1, '00001', 1, '2014-06-01', 20), 
    (2, '00001', 1, '2014-06-03', -10), 
    (3, '00001', 1, '2014-06-07', 30), 
    (4, '00002', 2, '2014-06-02', 15), 
    (5, '00002', 2, '2014-06-03', -5), 
    (6, '00002', 2, '2014-06-05', 20);
    My guess is that yoyu can use: 
     CREATE VIEW Inventory_Levels
    AS
    SELECT sale_date, gtin, sale_qty,
           SUM(sale_qty) 
           OVER (PARTITION BY gtin
           ORDER BY sale_date
           ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) 
           AS current_stock_qty
      FROM Sales_Transactions 
     GROUP BY sale_date, gtin, sale_qty;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Formula help - Group totals for more than one date range

    Post Author: melcaylor
    CA Forum: Formula
    I need to show in 3 columns
    inside of a grouping that totals an amount field based on a date
    range that amount was posted.  So for example:
    Billy Bob in the state of MA made $5.5m total, $800k in the last 21 days, $400k in the last 14 days and $150k in
    the last 7 days.
    I assume this is possible but I
    just donu2019t know what type of formula to write to make it work.  For this
    example, there are 2 tables u2013 user table and $$ table.  The User table has
    the user name, the $$ table has the pay date and the amount. 

    Post Author: SKodidine
    CA Forum: Formula
    You only need simple formulae in Running Totals to accomplish this.
    1.  Group by Name
    2.  Create the following Running Totals:
    2.1 A running total to sum the pay amount for all records, and resets on 'Change of Group' of Name.
    2.2 A running total to sum the pay amount and for 'Evaluate' click on the radio button next to 'Use a formula' and then click on X-2 button next to it.
    In the formula workshop window type a formula such as: {table.payment_date} in (currentdate - 21) to currentdate;
    For 'Reset' click on the radio button next to 'On change of group' and pick the group name.
    2.3 Create another running total just as in step 2.2 above but change the formula to: {table.payment_date} in (currentdate - 14) to currentdate;
    2.4 Create the last running total just as in step 2.2 above but change the formula to: {table.payment_date} in (currentdate - 7) to currentdate;
    Hide the details section and in the group footer place text boxes with appropriate text and insert these running totals to give you the numbers you want.
    The only issue I see with this is if a person was paid yesterday a sum of $25, then it will show $25 for total, last 7days, last 14days and also for last 21days.  At first look it might be mistaken for $75.

  • What report is run in SAP to get the DATE on which Users are locked ?

    Hello,
    What report is run in SAP to get the DATE on which Users are locked ?
    I have tried with RSUSR200 ,-- last logon ,last password change , but i did not get a option to find the date on which are Users are locked .
    Can anyone suggest what report should be executed to get the date on which Users are locked and by whom ?
    As a alternate , i  am usig SUIM to get extract this data but i am looking for a report .
    thanks & regards
    Ganesh

    Hi Ganesh,
    You can try the below link where many of the options are described:
    How i can check at what date perticular user was locked and who lock it?
    Regards,
    Nilanjan

  • Running total for duplicate rows

    Hi,
    I am trying to write an sql which shows the running total for records which has duplicate. Please share any idea to get this.
    sample rows:
    col1 col2 col3
    1      A    2
    1      A    2
    1      A    2
    1      B    3
    1      B    3
    1      C    5
    1      D    2
    1      D    2o/p required:
    col1 col2 col3  cumulative_tot
    1      A    2       2
    1      A    2       2
    1      A    2       2
    1      B    3       5
    1      B    3       5
    1      C    5       10
    1      D    2       12
    1      D    2       12

    Hi,
    Try this:
    WITH A AS
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'B' col2, 3 col3  from dual union all
    select 1 col1,  'B' col2, 3 col3  from dual union all
    select 1 col1,  'C' col2, 5 col3  from dual union all
    select 1 col1,  'D' col2, 2 col3  from dual union all
    select 1 col1,  'D' col2, 2 col3  from dual
    ,B AS
    SELECT
      A.*
      ,ROW_NUMBER() OVER (PARTITION BY COL1, COL2 ORDER BY 1) RN
    FROM
      A
    SELECT
      B.*
      ,SUM(CASE WHEN RN = 1 THEN COL3 ELSE 0 END) OVER ( ORDER BY COL1, COL2 ,RN ) cumulative_tot
    FROM
      B
    COL1 COL2 COL3 RN CUMULATIVE_TOT
       1 A       2  1              2
       1 A       2  2              2
       1 A       2  3              2
       1 B       3  1              5
       1 B       3  2              5
       1 C       5  1             10
       1 D       2  1             12
       1 D       2  2             12
    8 rows selected Regards,
    Peter

  • Run SPRUNCONSO for some of the rules only

    Dear all,
       Is it possible to run SPRUNCONSO for some of the rules only?
       For example ,
       I got 10 rules defined in the rule table.
       I want to run 1~5 rules first ,after that run other functions or adjustment and last
       run the following 6~10 rules.
       Is this possible?
    Best Regards,
    Jeff

    Hi Alwin,
    Good point.
    But, I think in order to achieve that we also need to separate the source datsources,right?
    For example:
    sFirstrules- dFirstrules  
    sInput - dInput
    sFirstrulesELIM - dFirstrulesELIM
    sSecondrules - dSecondrules
    sInput2nd - dInput2nd
    s2NDrulesELIM - d2NDrulesELIM
    And, those s<datasources> are more like a staging data for each step.
    We might need to clean up those data after running those rules?
    Or,
    The system run the rules by the order of the adjustment id name?
    1 . ELIM01- dFirstrules  
    2.  ELIM02- dInput
    3.  ELIM03- dFirstrulesELIM
    4.  ELIM04 - dSecondrules
    Thank you for ur reply.
    Best Regards,
    Jeff

  • When we get the actual data in BPC for planning, is the data consolidated

    I had a question regarding Planning. When we get the actual data in BPC for planning, is the data consolidated? Do we need to run the consolidation business rules( IC Booking, Matching, IC Eliminations) on the data before we can use it for planning? Per my understanding we have to run Currency Conversion on this...correct?
    Also, where do I get my actual data from? Does ECC/ Source system have data from all entities( CHQ, Region and Countries)?
    Please help!
    Thanks in advance

    Hi Kimi,
    In a hierarchical structure, the data is always loaded in to the base level, and the data is automatically rolled up to its parents.
    The currency conversion will also take place at the base level, and as mentioned earlier, the converted data will also be rolled up as per the hierarchy.
    The heading of this thread says planning. So, ideally, there wont be any legal (or statutory) consolidation. You might use the US elimination however, for eliminating the intercompany transactions, if any.
    The planning can be done as zero based (wherein the user has to enter the planned data manually from scratch) or non-zero based (wherein the planned data of previous year is copied and the user can change the data as required).
    The flow of events cannot be suggested by us. It has to be discussed with the business to understand how do they do the planning.
    Hope this helps.

  • I want to take a series of hex characters in a string control and produce an HDLC string indicator for example if the data string control is 3F27 then the HDLC string indicator is 7E003F2700B57E

    I want to take a series of hex characters in a string control and produce an HDLC string indicator for example if the data string control is 3F27 then the HDLC string indicator is 7E003F2700B57E

    "thanks for your help "
    Does that mean you figured it out already?
    If not, see this thread for some HDLC related code.
    http://forums.ni.com/ni/board/message?board.id=170&message.id=146859&query.id=3388#M146859
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Changing date format for some of the date columns in a subject area

    Hi,
    I have a requirement to change the date format for some of the date columns to dd-mon-yyy for only a particular subject area. Is there a feature available in the RPD which can help me do this?
    In Answers - Column Properties for a Particular column of a report, we can save the style and formatting as system wide default for the particular column or the data type, but that applies across subject areas.
    I tried with the config files too , but that too applies to all suject areas.
    Thanks in Advance,
    Gaurav

    Why don't you create 2 logical column derived from same date physical col and then change the format for one logical column and use it in Subject Area ?

  • How to filter the data in different sections (e.g. Report Footers)?

    Hi,
    I am using Crystal Reports 11 to generate cross-tables.
    I plan to generate 3 cross-tabs, and each cross-table will be put in a section. For example, cross-tab1 in Report Footer a; cross-tab2 in Report Footer b; cross-tab3 in Report Footer c.
    I know use "Select Expert" to filter data. But, it seems that "Select Expert" filters data for the whole report.
    I want to filter the data for each cross-table separately. For example, filter cross-tab1 based on condition1; filter cross-tab2 based on condition2; filter cross-tab3 based on condition3.
    How to filter the data in different sections (e.g. Report Footers)?
    Thank you in advance.

    Hi,
    Now that you've inserted the subreport just right-click the sub-report and click Edit. The Design page for sub-report should open up.
    You can now insert the cross-tab on the Report Header and insert a record selection formula of your choice.
    Also, suppress all the other sections of the subreport so the Main report only shows the crosstab without any spaces.
    Do the same for all the subreports.
    -Abhilash

  • Running total for item availbe qty. from On Hand - SO + PO by promise date

    I stuck with Balance(running total).
    How to link item number with SO and PO?  
    Need daily item qty. available qty from "On Hand" Qty. + PO - SO by promise date and sort by ascending?
    Item#    Order Date  SO/PO   PromiseDate  Qty   Bal.
    AE01    08/01/08     OnHand                       20     20
                08/02/08     SO#1877   08/05/08       -3    17
                08/04/08     SO#2044   08/08/08       -6    11
                07/22/08     PO#632     08/10/08      10   21
    Thanks.

    create a group by promise date
    2nd group by po#
    put the fields either in the group or in the details
    PO#, PO promise date, qty and SO#, SO promise date, qty then availability qty
    manual running totals
    create 3 formulas
    1 reset
    WHILEPRINTINGRECORDS;
    NUMBERVAR ITEMLOC := 0;
    place in the group header on what you want the total to reset by (po#)
    1 calc
    WHILEPRINTINGRECORDS;
    NUMBERVAR ITEMLOC := ITEMLOC +(qty};
    this gets placed where the calculate will take place (next to qty)
    1 display
    WHILEPRINTINGRECORDS;
    NUMBERVAR ITEMLOC;
    ITEMLOC
    this gets placed in the group footer.
    for each field that gets calculated by a group create 3 formulas for each
    they need to have the same variable name to reference each other.
    if you need to create a 2nd set to calc something else give that a new variable name.

  • Calculate running total

    I want to calculate the running total on a bank account with each transaction.
    Below is sample data script.
    CREATE TABLE ACCT (trans_type varchar2(100), trans_date date, trans_loc varchar2(250), trans_amt number);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('11/19/2010', 'MM/DD/YYYY'), 'WAL-MART', 2.62);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('RETURN', TO_DATE('12/27/2010', 'MM/DD/YYYY'), 'JCPENNEY STORE', -32.27);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('11/28/2010', 'MM/DD/YYYY'), 'WAL-MART', 23.91);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('01/02/2011', 'MM/DD/YYYY'), 'TOMMY HILFIGER', 16.1);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('02/27/2011', 'MM/DD/YYYY'), 'DILLARD''S', 64.31);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('01/07/2011', 'MM/DD/YYYY'), 'MIKE KEHOE', 23.26);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('01/02/2011', 'MM/DD/YYYY'), 'OLIVE CAFE', 25.04);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('12/10/2010', 'MM/DD/YYYY'), 'WAL-MART', 46.13);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('12/07/2010', 'MM/DD/YYYY'), 'WAL-MART', 3.82);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('12/01/2010', 'MM/DD/YYYY'), 'TARGET', 12.09);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('02/22/2011', 'MM/DD/YYYY'), 'TARGET', 43.1);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('01/26/2011', 'MM/DD/YYYY'), 'ST MARYS BIL', 6.96);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('02/14/2011', 'MM/DD/YYYY'), 'WALLMART', 56.9);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('02/27/2011', 'MM/DD/YYYY'), 'WALLMART', 43.64);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('01/16/2011', 'MM/DD/YYYY'), 'OLIVE CAFE', 18.14);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('SALE', TO_DATE('12/23/2010', 'MM/DD/YYYY'), 'MIDEAST BALLWIN', 103.18);
    Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
    Values ('RETURN', TO_DATE('12/27/2010', 'MM/DD/YYYY'), 'JCPENNEY STORE', -34.75);I need running total to show with each transaction and also the balance amount out of a static limit of 7500.
    Any help is appreciated!

    Thanks for providing sample data!
    Are you looking for something like this?
    SQL > SELECT trans_type
      2       , trans_date
      3       , trans_loc
      4       , trans_amt
      5       , 7500 - SUM(trans_amt) OVER (ORDER BY rn) AS running_balance
      6       , SUM(trans_amt) OVER (ORDER BY rn)        AS running_total
      7  FROM   (
      8                  SELECT trans_type
      9                       , trans_date
    10                       , trans_loc
    11                       , trans_amt
    12                       , ROW_NUMBER() OVER (ORDER BY trans_date) AS rn
    13                  FROM   acct
    14         )
    15  ORDER BY 2
    16  ;
    TRANS_TYPE      TRANS_DATE          TRANS_LOC                            TRANS_AMT      RUNNING_BALANCE        RUNNING_TOTAL
    SALE            11/19/2010 00:00:00 WAL-MART                                  2.62              7497.38                 2.62
    SALE            11/28/2010 00:00:00 WAL-MART                                 23.91              7473.47                26.53
    SALE            12/01/2010 00:00:00 TARGET                                   12.09              7461.38                38.62
    SALE            12/07/2010 00:00:00 WAL-MART                                  3.82              7457.56                42.44
    SALE            12/10/2010 00:00:00 WAL-MART                                 46.13              7411.43                88.57
    SALE            12/23/2010 00:00:00 MIDEAST BALLWIN                         103.18              7308.25               191.75
    RETURN          12/27/2010 00:00:00 JCPENNEY STORE                          -34.75                 7343                  157
    RETURN          12/27/2010 00:00:00 JCPENNEY STORE                          -32.27              7375.27               124.73
    SALE            01/02/2011 00:00:00 OLIVE CAFE                               25.04              7350.23               149.77
    SALE            01/02/2011 00:00:00 TOMMY HILFIGER                            16.1              7334.13               165.87
    SALE            01/07/2011 00:00:00 MIKE KEHOE                               23.26              7310.87               189.13
    SALE            01/16/2011 00:00:00 OLIVE CAFE                               18.14              7292.73               207.27
    SALE            01/26/2011 00:00:00 ST MARYS BIL                              6.96              7285.77               214.23
    SALE            02/14/2011 00:00:00 WALLMART                                  56.9              7228.87               271.13
    SALE            02/22/2011 00:00:00 TARGET                                    43.1              7185.77               314.23
    SALE            02/27/2011 00:00:00 WALLMART                                 43.64              7142.13               357.87
    SALE            02/27/2011 00:00:00 DILLARD'S                                64.31              7077.82               422.18
    17 rows selected.

  • Getting running total formula result at the beginning of the report

    Hello All,
    I am having an inquiry that if I can get a grand total in the report footer to the report header.
    The grand total is not a direct sum.  I am using three formulas
    the first formula:
    @reset Group Header
    whileprintingrecords;
    numbervar sumpct4;
    if not inrepeatedgroupheader then
    sumpct4 := 0;
    the second formula: Details section
    whileprintingrecords;
    numbervar sumpct4 := sumpct4 + {@Total_Market};   // {@Total_Market}; =  Amount+ Interest
    numbervar grtotal4 := grtotal4 + {@Total_Market};
    Group Footer
    whileprintingrecords;
    numbervar sumpct4;
    Report Footer
    whileprintingrecords;
    numbervar grtotal4;
    All that I need is to show the total which is in the report footer at the top of the page where I am having a summary.
    So, can you please help me.
    Thanks
    Edited by: maas maas on Sep 8, 2010 12:48 PM

    Hello my friend,
    I want this to be controlled in crystal.
    Is there is a way to get the grand total by using multiple formulas or any other way?
    Here is the structure of my report:
    Group Header 1: CCY
    Group Header 2:Type
    @reset Group Header
    whileprintingrecords;
    numbervar sumpct4;
    if not inrepeatedgroupheader then
    sumpct4 := 0;
    Group Header 3A: Deal No
    Group Header 3B: Deal No (subreport to get the {@amount} for each deal)
    I will pass the end_date from the main report to subreport and I will get the sum(amount) for each deal between date (1-1-2008) to end_date. The sum will be as a shared variable to the {@amount} formual in the main report.
    Details:
    Deal No, {@amount}, {@Price}, {@market}, {@Total_Market}
    {@Price}: if {table.price} = 0 then
    100
    else {table.price}
    {@market}: if Type <> "DEP" then
    ({@amount}*{@Price})/100
    else
    {@amount}
    {@Total_Market}:{@market}+ {@Price}
    Running formula to get Total_market: Details section
    whileprintingrecords;
    numbervar sumpct4 := sumpct4 + {@Total_Market};
    numbervar grtotal4 := grtotal4 + {@Total_Market};
    Group Footer 3B: Deal No
    Group Footer 3A: Deal No
    Group Footer 2:Type
    In this group I am placing a running total formula:
    whileprintingrecords;
    numbervar sumpct4;
    Group Footer 1: CCY
    Report Footer:
    @grand_Total
    whileprintingrecords;
    numbervar grtotal4;
    Now, i want this @grand_total formula result to be shown in Group Header 1: CCY.
    I tried to insert a subreport at the beginning which it is a copy of the main report, but I did not get the coorec t result because I am getting the {@amount} from a subreport and in crystal I can't insert a subreport in an existing subreport.

  • Running Total for "cleared balance"

    I want to produce query that will produce two running totals. The 1st once is straight forward and is 'Ledger Balance' - that is the balance after a particular transaction has taken place on that day. The Cleared Balance is the running total balance accounting for the value date of a transaction. For example a transaction for today, say $50 may be value dated tomorrow and hence is included in the Ledger Balance but would not appear in the Cleared balance until tomorrow.
    Lets try and use some simple data:
    TransactionsTable                    
    Tran_ID     TranDate     ValueDate     Amount
    1     01/02/2004     01/02/2004     50
    2     01/02/2004     01/02/2004     25
    3     01/02/2004     05/02/2004     30
    4     01/02/2004     01/02/2004     55
    5     02/02/2004     04/02/2004     11
    6     02/02/2004     02/02/2004     23
    7     02/02/2004     02/02/2004     33
    8     02/02/2004     02/02/2004     47
    9     04/02/2004     04/02/2004     10
    10     07/02/2004     07/02/2004     5
    StatementHistory                    
    AC_No     Start_Date     End_Date     Opening_Ledger     Opening_Cleared
    55     02/02/2004     02/02/2004     160          130
    55     04/03/2004     04/02/2004     274          233
    Assuming that the account opened on the 01/02/04 with a zero balance.
    So for a daily statement on the 01/02/04, I'd expect to see the following Details     
    TranDate     ValueDate     Amount     Ledger Balance     Cleared Balance
    01/02/2004     01/02/2004     50     50          50
    01/02/2004     01/02/2004     25     75          75
    01/02/2004     05/02/2004     30     105          75
    01/02/2004     01/02/2004     55     160          130
    So for a daily statement on the 02/02/04, I'd expect to see the following Details
    TranDate     ValueDate     Amount     Ledger Balance     Cleared Balance
    02/02/2004     04/02/2004     11     171          130
    02/02/2004     02/02/2004     23     194          153
    02/02/2004     02/02/2004     33     227          186
    02/02/2004     02/02/2004     47     274          233
    And skipping to the 04/02/04, I'd expect to see.
    04/02/2004     04/02/2004     10     284          254
    I can get the ledger balance using:
              sum(amount_to_account) OVER (PARTITION BY ac_no , trans_ID
              ORDER BY TranDate, trans_ID
              RANGE UNBOUNDED PRECEDING)
         + sh.Opening_Ledger
    But I'm unsure how to get the Cleared balance as this need to access transaction inforation from a number of days previous (possibly up to 5 days allowing for maximum period for clearing a transaction).
    Does anyone have an idea how to achive this?

    Hi,
    Try this:
    WITH A AS
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'A' col2, 2 col3  from dual union all
    select 1 col1,  'B' col2, 3 col3  from dual union all
    select 1 col1,  'B' col2, 3 col3  from dual union all
    select 1 col1,  'C' col2, 5 col3  from dual union all
    select 1 col1,  'D' col2, 2 col3  from dual union all
    select 1 col1,  'D' col2, 2 col3  from dual
    ,B AS
    SELECT
      A.*
      ,ROW_NUMBER() OVER (PARTITION BY COL1, COL2 ORDER BY 1) RN
    FROM
      A
    SELECT
      B.*
      ,SUM(CASE WHEN RN = 1 THEN COL3 ELSE 0 END) OVER ( ORDER BY COL1, COL2 ,RN ) cumulative_tot
    FROM
      B
    COL1 COL2 COL3 RN CUMULATIVE_TOT
       1 A       2  1              2
       1 A       2  2              2
       1 A       2  3              2
       1 B       3  1              5
       1 B       3  2              5
       1 C       5  1             10
       1 D       2  1             12
       1 D       2  2             12
    8 rows selected Regards,
    Peter

  • Add Total for a Column in Data Grid Screen Based on Query

    Hi Guys , I have query based on table Payments in which I search By Start Date , End Date  and tenant person [ from drop down List ].
    How to display sum of Payments.[Amount] column in the query screen , which off-course varies for selected person.
    Omar 

    The data grid doesn't support calculating aggregate functions on columns automatically, but you can write a little bit of code to show the total of the payments right beneath the data grid.
    Add a screen member called PaymentsTotal that is the same type as the column that you want to sum.
    Drag out the screen member to be underneath the data grid. You can change the sizing settings (e.g. Horizontal Alignment) so that it aligns with the data grid how you want it.
    Select the Payments collection and select Payments_Changed from the Write Code drop down.
    In the generated method, write the following code:
    partial void Payments_Changed(NotifyCollectionChangedEventArgs e)
    // Total is the name of the property in my Payment entity that I want to sum
    this.PaymentsTotal = this.Payments.Sum(p => p.Total);
    When you run the screen, the PaymentsTotal property will show the total of all of the payments that are shown in the data grid.
    Justin Anderson, LightSwitch Development Team

Maybe you are looking for

  • How to restrict duplicate rows..

    Dear Guru's.. I have below query.. When i run this query i need to get two rows.. But iam getting two more duplicate rows.. I want to restrict these two rows.. How can i do this.. Here the problem is when i join B qery then only iam getting duplicate

  • How do I perform a "Suite Product Activation" so that Acrobat will start working on my new Retina MacBook Pro?

    How do I perform a "Suite Product Activation" so that Acrobat will start working on my new Retina MacBook Pro? Like others, I have recently upgraded my MacBook Pro to the next generation and migrated all my information from old to new. Everything wor

  • What is the most recent word on antivirus programs?

    Are Macs still pretty much immune, or should we be considering using an antivirus program; and if so, what?  I know that the word used to be that Mac users didn't need to worry too much but don't know if that still holds true. Thanks, in advance, for

  • International product pricing

    I have been a loyal customer of Photoshop CS for years now, and religiously buy every upgrade. I live in Spain but use an English OS, and therefore always buy English language versions. When I saw that CS6 was available I went to the main Adobe.com w

  • Forum for XML Publisher

    Hi, Is there a separate forum for XML publisher? :) I got this white paper: Check Printing Using XML Publisher in Oracle Applications Release 12 An Oracle White Paper January 2007 Oracle XML Publisher offers integrated functionality that allows custo