Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I combine a SUM formula with an IF formula?

Status
Not open for further replies.

jizzycrystal

IS-IT--Management
Nov 10, 2007
65
IE
I want to say:
sum (if {@formula1} = 10 then {formula2})+(if{formula3}=12 then {formula5})
my syntax must be wrong...how do I lay it out?
Thanks
 
Split it into several formula fields, with test and a result of zero if it does not pass. You can then reference each by name.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
But I have about 20 "IF THEN" statements that I want to SUM I don't want to have to create 20 formulaes and then a SUM formula
 
you can write the whole thing in one formula using variables. use variables to evaluate each function and sum up all the variables in the end. it will look like this
declare the variables first
var1:=@Formula1(you can put the expression which evaluates this formula ;
var2=@formula2;
------------
varn=@formulan;

now you can play around with if conditions or run a sum expression using these variables to get your result
watch out for the datatypes and initialisation.
Hope this is what you were looking for.

Thanks,
Madhu
 
Hi Thanks for replying but I don't know anything about variables. could you just help me fix the syntax for this formula
((IF {@3rd_element} = '10' then {@Period_AMT}) OR (IF {@3rd_element} = '13' then {@Period_AMT}) OR (IF {@3rd_element} = '16' then {@Period_AMT}) OR (IF {@3rd_element} = '19' then {@Period_AMT}) OR IF {@3rd_element} = '22' then {@Period_AMT}) OR (IF {@3rd_element} = '25' then {@Period_AMT})

by the way not too sure if I should be using "AND" or "OR"
I want to add them
 
Since all the results are {@Period_AMT}, I am not sure what you are trying to accomplish. I expect to se am else result somewhere. Try this syntax:

If {@3rd_element} in ['10','13','16','19','22','25'] then {@Period_AMT} else ........

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"What version of URGENT!!! are you using?
 
Yes that works...thanks!!!
didn't know my thread was urgent...sorry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top