cancel
Showing results for 
Search instead for 
Did you mean: 

Condition on a variable

0 Kudos

How to make a condition on a sum in a report. Do I need to create a another variable that will allow me to take the sum and transfer it to variable and put a "Yes" Or "No" condition on it?

Accepted Solutions (0)

Answers (1)

Answers (1)

DellSC
Active Contributor
0 Kudos

Where do you want to use the condition? Before or after the sum is calculated? Crystal will not let you use a condition based on a sum before the sum is actually calculated.

-Dell

0 Kudos

After the sum is calculated.

DellSC
Active Contributor
0 Kudos

I think I know how to get this to work....

1. Create a formula that calculates the sum:

{@CalcSum}
Numbervar mysum := Sum({MyTable.MyField}, {Group field})

If you want the grand total, leave out ", {Group field}"

2. Create a formula that returns true or false. In this case, I'm just going to look for the sum being greater than 0:

{@IsNotOk}
EvaluateAfter({@CalcSum}); 
Numbervar mysum;
mysum <= 0

Not that I did not use and if-then-else here - mysum <= 0 returns either true or false, so you don't need the if-then-else to get those values. You want this to evaluate to True for conditions where you want to NOT show the section.

3. On a section BELOW where you have placed the {@CalcSum} formula to show the sum, this means a group footer if you're calculating for a group or the report footer if you're calculating a grand total, go to the Section Expert. DO NOT check the Suppress checkbox. Instead, click on the formula button to the right of the checkbox and enter the following:

{@IsNotOk}

When {@IsNotOk} returns True, the section will be suppressed, if it returns False, the section will display.

-Dell

0 Kudos

This is the version of Crystal Reporting that I'm using:sap.png. I don't think the code will for work in this version.

DellSC
Active Contributor
0 Kudos

That's Crystal 2016 SP5, which is fairly new. This might or might not work, but it would be worth trying to see if it will.

-Dell