Print Page | Close Window

Running totals sum in Report Footer

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=14991
Printed Date: 06 May 2024 at 11:09am


Topic: Running totals sum in Report Footer
Posted By: achandana01
Subject: Running totals sum in Report Footer
Date Posted: 21 Nov 2011 at 1:47pm
Hello All,
 
I do have a table like this
 
Department Customer ID Purchase ID City
Laptops A123 101 Los Angeles
Laptops A123 101 Los Angeles
Tablets A123 101 Los Angeles
Laptops B123 102 Los Angeles
Laptops A123 102 Dallas
Smart Phones A123 101 Los Angeles
Smart Phones B123 105 New York
Laptops A123 107 New York
Tablets A123 108 Dallas
 
I need a summary like this way
 
  Los Angeles New York Dallas Totals
Laptops 2 1 1 4
Smart Phones 1 1 0 2
Tablets 1 0 1 1
Report Footer 4 2 2 8
 
Let see the scenerio
 
1) For Losangeles A customer named A123 bought two laptops with same Purchase ID and the same customer bought laptop in NY & Dallas with different PID's
2) For Los Angeles B123 bought another laptop with purchase ID 102
 
I grouped it by department and I am using Running totals to count the number at group footer
 
Field to Summarize -- > Department
Type of Summart --> Distinct Count
Evaluate : choose formula and I put city = "Los Angeles "
Reset : On change of group : Department
 
I am getting the correct number at group level but to get the totals at the report footer I have no clue how to write a formula/running totals for it.
 
To be precise all I need is just to sum all numbers at the group level to get a total at report footer.
 
Please give me suggestions on it,any help will be appreciated greatly.
 
 


-------------
chand



Replies:
Posted By: lockwelle
Date Posted: 22 Nov 2011 at 3:19am
as people have been pointing out lately, try a cross-tabs for the summary.  It should be exactly what you are looking for, and they're pretty easy to set up.
 
HTH


Posted By: achandana01
Date Posted: 22 Nov 2011 at 5:53am
Thank you for you suggestion, I tried it but I am still not getting the exact result at report footer which leaves me at the same  page where I am when I tried running totals hoever I learned somethign new today and thanks for that :).
 
I am getting something like this :
  Los Angeles New York Dallas Totals
Laptops 2 1 1 4
Smart Phones 1 1 0 2
Tablets 1 0 1 2
Report Footer 3 2 2 7
 
but I need like the following :
 
  Los Angeles New York Dallas Totals
Laptops 2 1 1 4
Smart Phones 1 1 0 2
Tablets 1 0 1 2
Report Footer 2 2 2 6
 
Because I am using distinct count I am not getting exact totals in the report footer
 
Could you please look into this one more time ?


-------------
chand


Posted By: lockwelle
Date Posted: 22 Nov 2011 at 8:06am
but the totals running vertically don't match?  what's that rule


Posted By: achandana01
Date Posted: 22 Nov 2011 at 8:11am
Nope they don't match.
 
The rule is to do a distinct count on purchase ID by department wise and
 
For report footer I need the sum of all the values at the group level not by distinct count of all purchase ID's


-------------
chand


Posted By: lockwelle
Date Posted: 23 Nov 2011 at 4:41am
it sounds like you want something like this:
shared numbervar LA;
local numbervar dLA:=distinctcount({table.field}, {group});
LA := LA + dLA;
dLA
 
I am just not sure how you will get the LA specific entities, but this will display the distinct count in the department footer and in the report footer you would have something like:
shared numbervar LA;
LA
 
and this will display the sum of the distinct counts in the report footer.


Posted By: achandana01
Date Posted: 23 Nov 2011 at 1:21pm
Your formula is working really well in getting the totals by department however I just forgot to include a condition at the department level I need to be break down by each city
 
shared numbervar LA;
local numbervar dLA;
if(city = "LA")=distinctcount({table.field}, {group}) ;
LA := LA + dLA;
dLA
 
Does this work or will that be a separate condition


-------------
chand


Posted By: lockwelle
Date Posted: 28 Nov 2011 at 5:00am
depends on how your report is structured...it's been a long weekend so details are fuzzy.
 
if you are displaying the count, by department and city, you probably just need to have a formula like:
shared numbervar LA;
shared numbervar xx;
 
local numbervar dc:=distinctcount({table.field}, {group});
if city = "LA" then LA := LA + dLA
else if city = "XX" then xx := xx + dc
  else...
dc
 
 
but if you are doing the subtotal somewhere else the formula would be different.
 
with the above method, you would display in the summary by creating formulas like:
shared numbervar LA;
LA
 
HTH


Posted By: mini987
Date Posted: 01 Dec 2011 at 9:46pm
hello!
i have also problems with total sum

my table looks like this

paper                                   number
sora press_80_70x100        28 600
imitex_140_70x100              340
sora press_80_70x100        28 600

what I need is to sum the same paper in the new column, and that that looks like this

paper                                   number           sum
sora press_80_70x100        28 600
imitex_140_70x100              340
sora press_80_70x100        12 000           40 600


can you please help me??



Posted By: lockwelle
Date Posted: 02 Dec 2011 at 3:22am
this becomes complex...
most of the time when you do a running total it's a total for a group, but here you want to have individual running totals by item, which is a bit more complex.
 
I have 2 possible solutions, neither of which is completely simple:
1) create a delimited string listing the item and its total which is maintained by adding/modifying the string
2) creating 2 arrays, 1 to hold the item and the second to holds it total
 
you may need to reset these methods as well, but from the snippet above, you wouldn't.
 
the delimited string would be something like |itemID^currentTotal|item^currentTotal|...
 
so you would use instr(totalString, "|" + {table.itemID} + "^") if this is > 0 then you would want to retrieve from initial pipe (|) to the next pipe and string current value, update it, display it, and then re-encode the value and insert it back into the string.  If the instr() = 0 , then you would just encode and add to the string.
 
if you are using arrays, you would initially dim 2 arrays to a size that is large enough to hold the items, say 100 or so to start.  (we can dynamically resize the array, but initially I would try to stay away from that).  Then you would search one of the arrays for the itemID, and if you find it, you can look in the other array at the same index for the value, increment it, display it, and just update the array.  If you don't find the itemID, you update the 'last' array element to hold the new itemID and update the count in the other array for the same index.
 
Neither is simple, but neither is it impossible.
 
HTH


Posted By: achandana01
Date Posted: 03 Dec 2011 at 11:34am
Hi Lockwell,
 
I used the formula in my report
 
shared numbervar LA;
shared numbervar xx;
 
local numbervar dc:=distinctcount({table.field}, {group});
if city = "LA" then LA := LA + dc
else if city = "XX" then xx := xx + dc
  else...
dc
 
I used the following to display summary at group level
 
shared numbervar LA;
LA
 
but for some reasons it is giving me a 0 I belive it is not taking any value from the if clause which we used to get the count.
 
Thank you for your help lockwell I really appreciate it.
 
 


-------------
chand



Print Page | Close Window