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! :)

Who is Participating?
peter57rConnect With a Mentor Commented:
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}
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;
For Target total for Header_01...

numbervar 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.

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 (^__^)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.