Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Need help with formula Post Reply Post New Topic
Author Message
deniscok
Newbie
Newbie


Joined: 11 Mar 2013
Online Status: Offline
Posts: 2
Quote deniscok Replybullet Topic: Need help with formula
     Posted: 11 Mar 2013 at 9:15am
in Crystal reports XI, I am trying to create the following report:

Group by customer

sum revenue for each customer based on an attribute of the order:

if order has attribute 'a' only, if order has attribute 'b' only or if order has
both attributes 'a' & 'b'.

For the customer group level totals I am all set.

I'm having trouble with getting the report totals for the case where the order has both attribute 'a' and 'b' only.  No matter what I've tried I keep getting the total for the case where attribute 'a' or 'b' is present, which is essentially all records.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Mar 2013 at 11:19am

do you define an order being in one of these categories by a single row of data or multiple rows of data?

IP IP Logged
deniscok
Newbie
Newbie


Joined: 11 Mar 2013
Online Status: Offline
Posts: 2
Quote deniscok Replybullet Posted: 11 Mar 2013 at 12:23pm
do you define an order being in one of these categories by a single row of data or multiple rows of data

it would be a single row; short version for customer record would be something like:

customerid, order#, attribute A, cost
customerid, order#, attribute B, cost

the customer may have one or the other or both, but when the customer does have both they would always be two separate records as shown above.


for the customer totals I created a running total for the customer group where only the A attribute was present, and a running total for the customers with only the b attribute.

Then to get total for customers with both attributes I created a formula that totaled only when both of the other two scenarios above where > 0 because in the combined column I only want the revenue total where the customer has both A & B.  Not sure if this was the best way to go about it, but it did give me the results I needed at the customer group level.

I now have a report footer total for orders with A only, and one for orders with B only, but the same logic I used above wont work.


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Mar 2013 at 5:11am
you will need two flags to set customer groups as to what category they are in
//A
if field.attribute='A' then 1
//B
if field.attribute='B' then 1
 
sum each of these at the customer level
sum(@A,customerid)
sum(@B,customerid)
 
now you can use Running totals with evlauation formulas to all of your values per customer where they fall into one of your 3 categories
 
all 3 running totals are the same other than the evaluation formula (and RT name)
name=SumAonly
field to summarize=revenue
type=sum
evaluate=use a formula
sum(@A,customerid)>0 and sum(@B,customerid)=0
reset = never
use in report footer
 
repeatr the other two but change hte evaluation fomrulas
//for B only
sum(@A,customerid)=0 and sum(@B,customerid)>0
//for A and B
sum(@A,customerid)>0 and sum(@B,customerid)>0
 
IP IP Logged
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