Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Sum of mixed data Post Reply Post New Topic
Author Message
zico
Newbie
Newbie


Joined: 03 Jun 2014
Location: Poland
Online Status: Offline
Posts: 1
Quote zico Replybullet Topic: Sum of mixed data
    Posted: 03 Jun 2014 at 7:32am
Hi

Here is example:

Color   Car Amount
Green   BMW    2
Green   Audi   1
Green   VW     7
Red     BMW    3
Red     VW     1
Yellow Opel   6

I want to add another column, which show sum of Amount, grouped by Car, just like that:

Color   Car Amount   Total
Green   BMW    2       2
Green   Audi   1       1
Green   VW     7       7
Red     BMW    3       5
Red     VW     1       8
Yellow Opel   6       6
Yellow BMW    3       8

I made function, but in my solution i have to write as many functions as cars so it doesn't make sense:

whileprintingrecords;
Global NumberVar BMW;

if Car = 'BMW' then
    BMW:= BMW + Amount
else
    BMW:= BMW;

Another idea? I tried running totals but i failed too.

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 05 Jun 2014 at 5:11am
I have 2 ideas:
1) create a shared string that is delimited and holds both car and sum...I've used this before and for me it would look like
|BMW@3|Audi@1|
then it is all string parsing and manipulating...new values are just added to the end

the other idea is to have 2 arrays, one with the name of the car in it and the other with sum

or a melding of the 2 solutions an array with a delimited string holding the name and the sum.

you could search the array fairly easily with something like:
if left(array[x], len({table.carname}) = {table.carname} then do something.

both of the last 2 suggestions with arrays would of course be done in a for loop with variables for found etc so that new cars are added to the end.

HTH
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 05 Jun 2014 at 6:42am
you could also try
grouping on car and color
then using the group heather 2 instead of details section
then create a formula like
sum(amount,car)
for total
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 05 Jun 2014 at 7:45am
wouldn't that give the same value all the time?

which if that is what is desired...
it just looked it was a running total grouped on color then car.

i've been wrong before, so it wouldn't surprise me
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.030 seconds.