Custom Running Total on Crosstab

Because I need to do some special calculations on a crosstab, I need to use the 'Supress' formula technique to do a custom calculations on a crosstab.
The crosstab exists in the report footer and everything works fine except when the crosstab is being expanded to the next page.  Basically, if the crosstab and it's grand total fits in one page, the calculation is fine.  If the crosstab requires another page, the grand total at the last page will only sum up the crosstab values on the page that the grand total is being displayed.
Is there any way to make it so that the grand total does not reset if it happens to expand to multiple pages?
Here are my formulas:
1.  Formula on Row 1 (Supress formula) - This will constantly add value to a variable as long as Row1 is printed.
whileprintingrecords;
numbervar grandtotal;
numbervar units;
numbervar budget;
grandtotal := grandtotal + (units * budget);
false;
2. Formula on Grand Total (Display String formula) - This basically displays the value of 'grandtotal' after all rows have been printed.
whileprintingrecords;
numbervar grandtotal;
'$ ' & totext(grandtotal);

You're using Crystal Syntax for your formulas, which I have to admit I'm not too familiar with...  But in Basic Syntax, there's a difference between Global and Shared variables, where Globals do not carry to the report footer but Shared variables do.
Perhaps if you use Shared variables instead of Globals (if that is what the syntax indicates) your problem will go away...
HTH,
Carl

Similar Messages

  • Running Total in Crosstab

    Hello all,
    I've been unable to find any solutions for my issue, and I'm desperately hoping someone smarter than me can help me out. I'm trying to create a running total across columns for a crosstab report.
    The report looks like the following, as best as I can format it:
    (date) JAN-09 FEB-09 MAR-09 APR-09
    7 7 24 13 <--
    (order type) (order #)
    Sales Order ACK12342 -4 -3 0 -1
    AHSKFD34 -2 -3 -2 0
    SSJDHD23 0 0 0 -10
    SJDDG1298 -5 0 0 0
    KDJD20937 -7 -8 0 0
    Work Order WO12620 9 0 0 0
    WO12827 8 7 0 0
    WO13743 3 7 19 0
    Stock N/A 5 0 0 0
    I want a running total of each month column. I've added the running total row I'm trying to create above. I haven't been able to create a running total that will give that to me.
    I hope this is enough information. I'll post answers to any followup questions.
    Thanks.
    EDIT: I apologize for the crosstab layout. I've butchered it, and I don't know how to go about making it more readable.
    Edited by: user3537345 on Sep 19, 2008 8:35 AM

    Hi Rod,
    Appreciate your response. Unfortunately, the solution you've posted doesn't go quite far enough.
    Your function does give me the running quantity, but it creates a new column for each OrderNumber, and then sums it. I've looking for a sum of all OrderNumbers (i.e., the whole column). Each column represents a month. So it's a running total of OrderNumbers, by Month. Hope that makes sense.
    I might be attempting to do something that can't be done in Discoverer. I'm just trying every suggestion I can get. I'm hoping it's something I've missed.
    I'll continue to experiment with your suggestion.
    Thanks.

  • Running Totals and Formulas with Cross Tabs

    Hi,
    I'm using Crystal Reports 2008 and am having two issues using Cross Tabs.
    The first is that I want to have two crosstabs. They both will have a common Y axis (Oppourtunity.Sales Rep), and on the Y Axis I want one to show all (Opportunity.Create Date) where (Opportunity.Staus = Won) and the other where (Opportunity.Staus = In Process), but I can't figure out how to contruct the formula to return this result.
    The other issue, is that in addition to summarizing based on Sum (Opportunity.Expected Revenue), I would also like to create a running total to show the cumulative (Expected Revenue) Week over Week.
    Any direction would be fantastic.
    Thank you,
    Michael

    Please go through the SAP Notes listed here which would help you how to create mannual running totals in crosstab
    [https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_ossnotes&query=runningtotalin+crosstab&adv=true&note_number=&component=&sdn_updated_on_comparator=GE&sdn_updated_on=&sortby=cm_rnd_rankvalue]
    Regards,
    Raghavendra

  • Customer Statement Report - running total

    Greetings,
    Example : Customer XYZ has 3 invoices, and on the 06/02/08 cheque World Bank Acc 100200 $800 paid for
    Inv 2000
    02/01/08 Inv #1000 $1000
    05/02/08 Inv #2000 $800
    04/03/08 Inv #3000 $600
    The statement should show as below:
    Date        Details                      Dr             Cr          Balance
    02/01/08   Inv #1000                    1000                         1000
    05/02/08   Inv #2000                     800                         1800
    06/02/08   World Bank 100200                             800         1000
    04/03/08   Inv #3000                     600                         1600
    Anyone worked on some form of balance / running total like that before in the PLD ?
    Thank you
    Edited by: Davinder Singh on Jan 13, 2009 10:17 AM

    Please check this thread:
    Re: Running Total in QLD
    Thanks,
    Gordon

  • Require a formula to calc the diff between 2 running total fields in a crosstab

    Post Author: PJM
    CA Forum: General
    Hi,
    I have built a crosstab in Crystal XI with the following columns:
    PROFILED BUDGET (a)                            EXPENDITURE TO DATE (b)                        VARIANCE (a-b)
    The profiled budget and expenditure to date columns are both running total fields.  I want the variance column to show the difference between the budget and expenditure. 
    To set the variance field up as a running total, I assume that I would have to specify that I want this formula evaluated after the budget and expenditure fields , however, I can't work out how to do this on a crosstab. 
    Moving the crosstab to the report footer has had no impact.
    If I try to create a basic formula using the running totals, I get the error message "A summary has been specified on a  non-recurring field" - I can't find an explanation of this error message on the help menu.
    Can anyone help with this please?

    overtime hours are calculated after 40. If I work 12 on monday, thats 12 regulars hours. not sure about others states laws but here in wisconsin we consider overtime after 40 only, not after 8 daily. at least thats how my company calculates overtime. lets say I work 10 hours a day, monday thru thursday, thats 40 hours regular time. anything after that is overtime. our weekly work schedule starts on sunday and ends on saturday. so on my bi-weekly time log, if i work 10 hrs a day monday thru thursday, i want 10hrs each day in regular hours cell, then when i work friday and or saturday, i want those hours in overtime hours. the main problem im having is: if i reach 40 hours in the middle of a day, i want the regular of that day to end and the overtime to pick up on the same day.
    here is a basic example of how i want regular and overtime to look. of course the values will be duration not just numbers. hope this helps explain what i need a bit better.

  • Running total and Next function in Crosstab

    <strong><font size="3"><font face="Times New Roman">Clarifications on getting Next Running sum and count on a Crosstab</font></font></strong><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Here is the example, which I am working on:</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Highlights of the Report:</font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt &#39;Times New Roman&#39;">         </span></span><font size="3">Report is grouped on {Scenario Name}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt &#39;Times New Roman&#39;">         </span></span><font size="3">Left side dates on any of the tables is {Version Date}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt &#39;Times New Roman&#39;">         </span></span><font size="3">Dates on the top header on any of the tables is {Fsc Week End Dt}</font></font></p><p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in" class="MsoNormal"><font face="Times New Roman"><span><font size="3">-</font><span style="font: 7pt &#39;Times New Roman&#39;">         </span></span><font size="3">Other formulae used in this report are:</font></font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">1) = ({Query1.Demand Qty})/100000</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Numerical values displayed in the "Original values" table.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">2) =</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">if {Query1.Scenario Name} = &#39;DLYPRD:ASCP-PRD:PRD&#39; </font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">THEN mid ({Query1.Scenario Name},13,3)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">ELSE mid ({Query1.Scenario Name},13,6)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Second column with value PRD in any of the tables.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">3) {next qty} = if not onlastrecord then next({@ShortDemandQty}) else 0;</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">(used in the "next values vertically" table)</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">4) - running total to calculate horizontally</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - For each record</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">5) - running total to calculate vertically.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - For each record</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Fsc Week End Dt}</font></p><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">In this report design, when I go and change the Sort order in the Record Sort Expert, some of the values go for a toss. I got two cases where the vertical values are correct in one case and horizontal values are correct in another case.</font></p><font face="Times New Roman" size="3"> </font><strong><font size="3"><font face="Times New Roman">First Case:</font></font></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Cumulative vertical values are correct.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal">&#160;</p><font face="Times New Roman" size="3"> </font><strong><font size="3"><font face="Times New Roman">Second Case:</font></font></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Cumulative horizontal values are correct.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal">&#160;</p><font face="Times New Roman" size="3"> </font><strong><span style="color: blue"><font size="3"><font face="Times New Roman">Is there any way to consistisize both the horizontal and vertical running totals. I even tried forcing the evaluate & reset like below and clearing the record sort order, but it did not work:</font></font></span></strong><strong><span style="color: blue"><font face="Times New Roman" size="3"> </font></span></strong> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">1) - running total to calculate horizontally</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - On change of field: {Fsc Week End Dt}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">2) - running total to calculate vertically.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Evaluate - On change of field: {Version Date}</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">Reset - On change of field: {Fsc Week End Dt}</font></p><font face="Times New Roman" size="3"> </font><strong><span style="color: blue"><font size="3"><font face="Times New Roman">And one more observation on the running total, how it works in the crosstab is, the total runs likes a spiral rather than resetting at the column or row level. Is there any way to restrict this?</font></font></span></strong><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">3) {next qty} = if not onlastrecord then next({@ShortDemandQty}) else 0;</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">(used in the "next values vertically" table)</font></p><font face="Times New Roman" size="3"> </font> <p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">For example, onlastrecord does not seem to work on the "next values vertically" crosstab, rather brings the record from the next column.</font></p><p style="margin: 0in 0in 0pt" class="MsoNormal"><font face="Times New Roman" size="3">For 3/7/2007 - 01/APR/07, the value is 157.84 which is incorrect and should be 0.</font></p><strong><span style="color: blue"><font size="3"><font face="Times New Roman">I need to get a next on the running total. Next (fld) doesnot work for running totals. Please guide me, how to get the next values for the running total fields.</font></font></span></strong>

    Post Author: redtop6683
    CA Forum: Formula
    Whoops I guess I should have mentioned that I've already tried using Sum and Round(Running Total, 2) and haven't had any luck.
    I also should have mentioned that Groupings 1 and 2 are sums, and that Running Total is a running total that changes on every change of the grouping.  There are 4 groupings.
    Grouping 1 (Employee Name)
    Grouping 1.1 (Shift)
    Grouping 1.2.1 (Payroll Department Code)
    Grouping 1.2.1.1 (Description)
    Below these 4 groupings is where the running total is.  The issue is that in the footer of grouping 1 is a field that sums the elapsed hours for the particular employee by each payroll department code, these are then summed using the running total.  The issue is as stated in the earler post that I can round these individual sums on the groupings, but I get the number on my running total to round differently as you can see by the earlier post's example.
    Thanks for the help.
    ~Jason

  • SSRS Running Totals Custom Code

    I have a report in which I need to total a column with an expression and created simple code to have a running total.  When I run the report through report builder, the total only reflects the current page (it is 6 pages long) but if I export the report
    out to Excel, the total is correct.
    Below is the code:
    Public running_roy as Double = 0
    Public Function roy_tot(ByVal cust_type, ByVal roy, ByVal ret_value) as Double
    Dim temp_var as Double
    if cust_type = 0 then
    running_roy = running_roy + roy
    if ret_value = 0 then
    temp_var = roy
    else
    temp_var = running_roy
    end if
    ELSE
    temp_var = 0
    end if
    return temp_var
    End Function
    If I change the Public variable to "Public Shared" the totals change as I flip back and forth between the pages in report builder.
    Any suggestions?

    Hello alan2624,
    Thanks for your clarification.
    In the report, the custom code will be compiled as a class before it is used. Every time the page is loaded, the class on the page will be initialized. The un-shared (non-static) instance will be reset. Therefore, you will see the value is reset back to
    zero if the public variable is not announced as "Shared". If you announced it as shared, then the variable is on the class level. It will not be changed by instance initializing. In addition, any operations on the variable will be recorded. This is not the
    bug, but it is by design of the VB.net code.
    If you export the report to the Excel, I think it will only generate a single page, and the total value is only the last one. It should be correct. If it is used in the pages in browser, I suggest you need design your code carefully for VB.net design.
    If you have any questions about this issue, please let me know.
    Regards,
    Edward
    Edward Zhu
    TechNet Community Support

  • Running totals: Custom Reset via Formula? (VS 2005)

    Post Author: PunchngMrGrumpy
    CA Forum: .NET
    Hi All,I have attached a screenshot to help make up for my inability to describe the situation I'm dealing with here.I
    have three groups within a report that currently use distinct Running
    Totals fields that Reset at the group levels that I assigned. I am
    attempting to create a single Running Totals field for all 3 groups
    that will reset depending on which Group is being calculated at the
    moment so that I don't have to have 3 separate Running Totals object
    for each and every group. I'm not sure how to do this or write this
    formula as I'm new to Crystal Reports and am used to SQL Reporting
    Services where this evaluation is automatically done for you (I was
    spoiled I guess).For example, if the Running Totals field
    control is in Group #1, I want it to reset at Group #1, and Group#2 to
    reset at Group #2, etc without having to create a field for each group.So
    basically I'm attempting to use a formula to create a Reset point (view
    screenshot for detail) that is determined by which group the data is
    being calculated in. Is this possible? I realize that it is possible by
    simply creating a new running total object for each group and telling
    it to reset on change of group specified, but this seems completely
    redundant and overly time consuming for larger reports where there are
    multiple groups and a lot of Running totals fields.I'm developing the report with Crystal Reports within Visual Studio 2005 if that helps any.I
    don't know if you'll be able to see it, but I have a screenshot link to
    explain what I'm trying to do. http://www.codeguru.com/forum/attachment.php?attachmentid=19302Thanks!

    Hi Abhilash,
    Thanks for the code, but the totals aren't right still yet.
    Also, I just noticed my running total is not functioning properly.  Count be the reason for my delima.
    Any suggestions on how to get the running total to function properly?
    What I just noticed is:
    Date               Patient          Count
    7/9/13             Patient A       7
    8/8/13             Patient B       8
    8/8/13             Patient B       8
    8/8/13             Patient C       8
    8/8/13             Patient D       8
    8/15/13           Patient E       9
    Would I be better off to do a formula vs a running total?

  • Item Transaction History Report - Calculation for creating 'Running Total'

    Hello
    Using Oracle Discoverer, we have written a report that pulls back all Inventory Transactions (by item number). This report lists both transactions IN (e.g. receipts into the store) and OUT (e.g. issues out from the store).
    Our customer would like an additional column, to represent 'Running Total', to be added to the report. This column needs to capture the running 'On Hand Quantity' for the associated Item, as each transaction (both transactions IN and OUT of store) is displayed.
    For example, if the initial/first transaction for an item was a Receipt of 500, then this column (on the first line) should display 500. If the second transaction for the item was an issue of 15, then this column (on the second line) should display 485. If the third transaction was for an issue of 50, then this column (on the third line) should display 435. If the fourth transaction was for a receipt of 20, then this column (on the fourth line) should display 455 etc etc
    I'm not sure how I'd write a calculation to cater for this (within discoverer) - do you know if this is achievable? Any help would be much appreciated. This would be easy enough to do in Excel, but I'm a bit of a novice when it comes to discoverer(!)
    Many thanks
    Ross

    Hi,
    You can generally do this type of calculation using analytic functions. You would partition by the item number and order by the transaction date in the analytic function. You can use SUM function (with an order by) to get a running total of a column in the report. You can SUM a calculation containing a CASE statement which changes the OUT transactions to a negative number. The SUM function will start at zero, so you then can use FIRST_VALUE function to get the first value for the item which you could then add to the totals.
    Rod West

  • Running total across 2 grouping

    Hi All
    I have created a crystal report and i have 2 remaining issues that i just cant get around.
    the report is basically about all the net stock position.
    the report is based on a query..that links sales order to all target documents that originate from the sales orders, i.e...deliveries, invoices, returns, credit notes.
    then i also brought in all the open purchase orders and the instock from the oitw
    i then sumed up the lines so the sales order > Delivery > invoice > credit note > returns all shows in one line..and if there is a different unit of measure it will be another line for that sales order
    the report is grouped:
                                  per warehouse
                                  per item
                                  per Sales Order Num
                                  per Item Unit of Measure
                                  per Line Num
    1st issue:
    in the selection criteria if the sales order is closed but if one of the delivery notes is open it should bring in the "whole set" not just the the open deliverys linked to the sales order.
    this is because the delivered quantities adds up to the net position of the stock.
    2nd issue:
    I have to work out a net postion
    formula: net stock = Oitw.instock + PO - remaining qty on sales order
    I got the sales order as a negative
    i used a running total formula, but it does not work if the sales order has more then one unit of measure.
    whileprintingrecords;
    If onfirstrecord or previous({Command.SO No.})<>{Command.SO No.} then
    numbervar remain_bal:= remain_bal + {@QTY}
    i tried to add another if statement..but does not work
    whileprintingrecords;
    If onfirstrecord or previous({Command.SO No.})<>{Command.SO No.} then
    If onfirstrecord or previous({Command.SO Uom)<>{Command.SO Uom.}  then
    numbervar remain_bal:= remain_bal + {@QTY}
    any help will be gladly welcomed..
    thank you all
    Jerusha

    Hi Dave
    Thank you very much for your feedback.
    I have been using the base UoM, ie InvQty field.
    my issues comes where i am grouping I am 1st grouping by sales order num, then by uom as the customer wants to see that as separate entries
    Example:
    SO Num     Uom     Qty     InvQty
    1               Bags     50         200
    1               Bulk     100        100
    This is the forumula for the running total:
    If onfirstrecord or previous ({Command.SO No.}) <> ({Command.SO No.}) then
    if ({Command.Doc Type}) = 'SO' then
        SO := SO + {@QTY}
    However when i "print" my total and add it to the footer.. it will show 200 instead of 300.
    Thanks
    Jerusha

  • Customer Ageing Total differ fron Balancesheet total.

    Hi All,
    Customer Ageing report doesn't matches with Debtors (Control A/c).
    Customer Ageing Total for the month of Jane.09 doesn't get match but Ageing total for the month of Feb09 does get match with control a/c .in Balancesheet.
    Kindly provide me the solutions .
    Thanks & regards,
    Harshad A.Surve.

    Hi,
    Can you check if you are running the Backdated Aging correctly.
    If you are working with 2005 version , please refer to Note No. 800294 and follow the settings mentioned in the Note.
    If you are working with 2007 version, run the report by checking the tickbox 'Display customers with zero balance'.
    Check if it helps.
    Regards,
    Jitin
    SAP Business One Forum Team

  • Running total in group header doesn't display when it's at page bottom

    Post Author: Charles Denight
    CA Forum: Formula
    Hi, Using v.9 of Crystal Reports I've created some running totals using a cross-tab workaround to get the running totals into the group headers, but when the group header falls at the bottom of the page then the running total doesn't show up.Would appreciate knowing why and how to fix this.

    Replacing an item that is malfunctioning because of a manufacturing error is the bare minimum I would expect from customer service for any electronics item.
    The thing Apple does extremely well is their flat fee policy for repairs on their computers.
    I managed to break my MacBook pretty seriously (logic board needed to be replaced) and I'm sure it cost them more to repair the unit than the $328 they charged me.
    I probably would have been angry if it was something minor, but I'm guessing that most repairs to screens/motherboards/etc cost more than their flat fees.

  • Running Total Variation Query Time Optimization

    Hi all, 
    I've been struggling with this query for a while. I need to set a customer specific running total for 10 million rows (reset for every customer). But every time the number goes negative, I need to set it as zero.
    For example,
    member no              amount            wallet
    member1                 400                      400
    member1                 -500                     0
    member1                  200                    200
    member2                  700                    700
    member2                 -200                    500
    Query:
    DECLARE @member float
    DECLARE @prev_member float
    DECLARE @amount float
    DECLARE @wallet float
    DECLARE db_cursor CURSOR FOR  
    SELECT [Member no], [Transaction Amount] 
    FROM [wallet_master_3]
    ORDER BY [Member No], [rownum]
    FOR UPDATE
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @member, @amount
    SET @prev_member = @member
    set @wallet=0
    WHILE @@FETCH_STATUS = 0
    BEGIN   
           IF @prev_member <> @member set @wallet=0
           SET @wallet = @wallet + @amount
           IF @wallet < 0 SET @wallet = 0
           UPDATE [wallet_master_3] SET walletsize = @wallet
           WHERE CURRENT OF db_cursor
           set @prev_member=@member
           FETCH NEXT FROM db_cursor INTO @member, @amount
    END   
    CLOSE db_cursor   
    DEALLOCATE db_cursor
    I've tried using a cursor. In five minutes, it ran 17,000 rows but after running it for 15 hours, the code only manages to set the running total for 175,000 rows. I'm not exactly sure why. Is there a faster approach I can use? 
    Thanks!

    As an exercise a 'Quirky Update' may help you in this scenario. Try the below trick!
    DECLARE @Wallet AS TABLE
    MemberNo VARCHAR(10),
    RowNum INT,
    Amount INT,
    Wallet INT
    INSERT INTO @Wallet (MemberNo, RowNum, Amount) VALUES
    ('member1',1, 400),
    ('member1',2, -500),
    ('member1',3, 200),
    ('member2',1, 700),
    ('member2',2, -200)
    DECLARE @RunTotal AS INT
    UPDATE W1
    SET
    @RunTotal = W1.Wallet =
    CASE
    WHEN W1.RowNum = 1 THEN W1.Amount
    WHEN @RunTotal + COALESCE(W1.Amount, W2.Amount) < 0 THEN 0
    ELSE @RunTotal + COALESCE(W1.Amount, W2.Amount)
    END
    FROM @Wallet W1
    LEFT OUTER JOIN @Wallet W2
    ON W1.MemberNo = W2.MemberNo AND W2.RowNum = W1.RowNum - 1;
    SELECT * FROM @Wallet;
    RESULT
    MemberNo RowNum Amount Wallet
    member1 1 400 400
    member1 2 -500 0
    member1 3 200 200
    member2 1 700 700
    member2 2 -200 500
    You can read more on 'Quirky Update' in below articles
    Solving the Running Total and Ordinal Rank Problems - Jeff Moden
    Robyn Page's SQL Server Cursor Workbench
    NOTE: Please test it thoroughly before using in a production environment!
    Krishnakumar S

  • How to create a running total formula for different calendar years

    Hello everyone,
    I am looking for some help in creating a running total formula for different calendar years in Oracle. This is what I currently have organized in the crosstab report: vertically I have the cities from our database organized, then horizontially have the following information for each city:
    2006 /2007 /2008
    Amount /Amount Spent /Unspent Amount Amount Recieved/Amount Spent /Unspent Amount Amount Recieved/Amount Spent/Unspent Amount
    Recieved
    I am trying to create a formula that will specify each calendar year. For example, I'd like to have a formula in 2007 which would total the: 2007= {2006 unspent amount + the unspent amount in 2007} and same for 2008= {2007 unspent amount + the unspent amount in 2008}. I hope this is clear, I have simplified the report into a basic interpretation of what i've been trying to accomplish.
    Would anybody know if this is possible and how to approach this?
    Really appreciate it! Thanks.
    Alex

    Hi,
    you can try and define a running total as a calculation in the crosstab as:
    sum(Unspent Amount) over (partition by city order by year)
    i find the crosstab format comfusing sometime since the aggregation is auto applied.
    I would start with a flat table and then "duplicate is as a cross tab"
    for your running total you can sort the data by the city,year and get it to 3 lines for each city, for example:
    city year Unspent Amount all other amount...
    X 2007 10
    X 2008 20
    X 2009 30
    Y 2007 5
    Y 2008 15
    Y 2009 25
    then you can use a funtion to calculate the amount :
    sum(Unspent Amount) over (partition by city order by year)
    this is the sql i used just to check it:
    SELECT city,year,"Unspent Amount"
    ,SUM("Unspent Amount") over (PARTITION BY city ORDER BY YEAR)
    FROM (
    SELECT 'X' city, 2007 YEAR, 10 "Unspent Amount" FROM dual UNION ALL
    SELECT 'X', 2008 ,20 FROM dual UNION ALL
    SELECT 'X', 2009 , 30 FROM dual UNION ALL
    SELECT 'Y', 2007 , 5 FROM dual UNION ALL
    SELECT 'Y', 2008 , 15 FROM dual UNION ALL
    SELECT 'Y', 2009 , 25 FROM dual
    Tamir

  • Manual Running Total vs Running Total

    Morning all,
    It is some what strange to me when I try to use a formula to calculate the total jobs and when I try to use Running total to count the same total jobs. Both answers in theory should be the same however they are not. I am wondering where am I going wrong in the manual formula.
    If {despatch_summary.job_type}="FSV" then
    if {despatch_summary.order_status}<>0 then
    {despatch_summary.order_no}
    else
    0
    The above code then gets DistinctCount ({@FSV})
    The same method if I use by using Running Total it gives the correct number of jobs.
    Running Total
    field to summarize : despatch_summary.order_no
    Summary Type: DistinctCount
    Formula: {despatch_summary.job_type}="FSV" and {despatch_summary.order_status}<>0
    Reset: none
    The formula gives me 513 where as the same running total gives me 514
    Where am I going wrong?
    Strangely it is adding 1 to all of my manual running totals (1 is coming from canceled orders).
    Many thanks
    Regards

    Sastry I am adding this formula into the crosstab which is setup by Number of days. So on the column it is number of days and on the summarized field it is this formula.
    I chose Group options and clicked on DistinctCount after adding the formula into the summarized field.
    I have already tried the formula you have suggested however it doesn't seem to be affecting it.
    Apart from that what I have just done is added the Running Totals to the Summarized field which is coming up correctly however now the problem is to get their percentages.
    I have used the following code but it doesn't seem to be working.
    Whileprintingrecords;
    Numbervar g:=Currentfieldvalue;
    Numbervar h:={@TotalJobs-CanceledJobs};
    Numbervar i:=0;
    i:=((g/h)*100);
    Numbervar gTot:=gTot+i;
    if gTot > 100 then "100.00%"
    else
    totext(gTot,2)+"%"
    I know I am doing it wrong when it comes to percentages. I need to get the percentages off that Running Total (Grand Total).
    Am not sure how to acheive that either.
    Many thanks
    Regards
    Jehanzeb

Maybe you are looking for

  • Linking to a specific SLIDING panel remotely

    I'm trying to link to a specific SLIDING panel (not a tabbed panel) from a remote link. I'm sure this can be done using SpryURLUtils.js as I've successfully achieved the result with tabbed panels. There's not as much online information on doing this

  • CRM CICO - Automatically complete follow on activities

    Hi all, In tcode CIC0 to automatically complete the activities I am trying to use BAPI BAPI_ACTIVITYCRM_CHANGEMULTI. I am forwarding the whole program too. Can anyone please tell me why the progrm si not working ? REPORT  z_crmorderread. DATA : lt_he

  • Transfer of Customer field for Confirmation

    Hello Expert, We are implementing Classic scenario for Self Service Procurement. We have implemented customer field in Confirmation for Goods. We want to know that how we can transfer the value of customer field to Backed GR? Your valuable inputs wil

  • Problems with tables in InDesign CS4

    Since recently upgrading to CS4, I've been having issues with editing strokes in tables. The problem occurs after working on a table for a while-- where at first I'm able to edit stroke color and weight fine, but then after a period of time it become

  • Safari Version 6.0 (8536.25) Can not memory my cookie!How is that?

    Safari Version 6.0 (8536.25) Can not memory my cookie!How is that?