How to use Sum (fld, condFld, cond)

Hello all,

I tried searching similar problems like this in Crystal Report section, but I couldn't find any. Do let me know if there's already a topic like this. Tq in advance!

I'm facing problem in using the Sum (fld, condFld, cond) formula.

This is my objective:
-------------------------
- To get total of Target Amount and Actual Amount and put it in Report Header (kindly refer to Attachment preview.jpg where red circles and purple circles indicate which data it should take as the total)


My design structure:
-------------------------
- Data being grouped by Region (in yellow color), each region has it's own Sales Target and Actual Sales. I've attached also the sql grid (if it's any help)
- My initial plan was to use the Sum (fld, condFld, cond) like this:

Sum (amount,type,where type='Target') but since we can only use boolean, date and time as condition, I tried putting a date column DTE_TEST, where Actual  Sales= sysdate-1, and Target Sales=sysdate (just to make it as indicator purpose).

- Therefore, when I tried to implement that in my formula, it gives error "This Group condition is not known" (as shown in attachment formula.jpg)

Hope I explained it clear enough! Would like to hear what experts might say about my problem. Thanks! :)



preview.jpg
formula.jpg
sql-script.jpg
yott-chanAsked:
Who is Participating?
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.

peter57rCommented:
Although the function you have used looks like it might do what you want, it really doesn't.
It is used for pulling out the total for one particular pre-defined group, not for summarising based on a new 'grouping' field.

To do what you want without using a subreport you can do this..(example shown for 2 columns only..)
Create a formula field to go into the detail line:

numbervar SumActual1;
numbervar SumTarget1;
numbervar SumActual2;
numbervar SumTarget2;

if {command.type}="Actual" then
(
Sumactual1 := sumactual + {Command.Header_01};
Sumactual 2:= sumactual + {Command.Header_02}
)
else
(
sumtarget1 := sumtarget+ {Command.Header_01};
sumtarget2 := sumtarget+ {Command.Header_02}
);
""
You then need further formula fields to display the results;these formula fields go in the report header.
For Actual total for Header_01..

for whileprintingrecords;
numbervar SumActual1;
Sumactual1
 
For Target total for Header_01...

whileprintingrecords;
numbervar SumTarget1;
sumtarget1
and so on.

Alternatively, you could create a subreport which just grouped the data by type and has grand totals for each Header_xx column.  You could then drop this in to the report header of the main report.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yott-chanAuthor Commented:
It works! It works! It works! It works! It works! It works!

Thanks peter57r!

I did think of doing a subreport just for the total as last resort, but thanks to you, I managed to do it in the formula!

Thanks again and God bless (^__^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.