# How can I use variables in crystal report and what is the diffrence between formula and variables in crystal report?

I have design a report which has parent child data. I am displaying my parent record in group header and child data in detail section. Now I want to do some subtotals in child data but this subtotal is based on some condition. Like if Currency is in CDN then add amount in VarCDN or if currency is in USD then add total in VarUSD. And I want these totals to be reset on group change. My problem is I dont know the sequance, step by step process to get the result. I dont have any link for crystal report help. I am little bit confuse between variables and formula. Every time I try to write formula I get the following error:
if {KHDaily1;1.PaymentMode} = "1 CASH CDN" then
numberVar cscdn := csdn + {KHDaily1;1.Part_Amt} ;
ERROR
A number, currency amount, boolean, date, time, date-time, or string is expected
thanks
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Variables are things which can be used in multiple spots inside of Formulas. Variables are not required to make a formula in Crystal. I've always had a little trouble with global variables (which I think must be your csdn field), especially when doing a running total. I'm just not good at them. :-) What you could try.
1 formula (let's call it ONE) doing:
if {KHDaily1;1.PaymentMode} = "1 CASH CDN" then {KHDaily1;1.Part_Amt} else 0

2nd formula would be sum(@ONE, @GroupName).

Crystal will automatically reset totals when you place them at the group level, so you might not need a variable at all.

Good luck, hope this helps.
Author Commented:
2nd formula would be sum(@ONE, @GroupName).
What do you mean by @GroupName?
Is it 2nd parameter in SUM ?
Can you explain ?
Do you know any site for crystal help ?

Commented:
Hi Khalid,

The 2nd formula syntax allows you to summarize. If you were to place your ONE formula into the detaul and the output looks like the following...
300
200
100

your TWO formula could be inserted in a group header or footer sum(@ONE, groupnamehere) and you would end up with output of 600 (300+200+100).

So far this is actually the best place I have found for Crystal Help. You can try to look on the businessobjects.com website, but I usually end up not finding what I need there.
Commented:
To summarize, I find it easier to drop the field or the formula onto the report in the detail section
Right click it
Click INSERT --> SUMMARY
Choose the footer I want it in.  It defaults to REPORT FOOTER but you probably want it inyour group footer.

As above create another formula to get the US dollars.

mlmcc

Experts Exchange Solution brought to you by