Sum of mixed data
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=20783
Printed Date: 02 May 2024 at 10:29pm
Topic: Sum of mixed data
Posted By: zico
Subject: Sum of mixed data
Date 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.
|
Replies:
Posted By: lockwelle
Date 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
|
Posted By: kostya1122
Date 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
|
Posted By: lockwelle
Date 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
|
|