Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Nulls Post Reply Post New Topic
Author Message
TokyoAnt
Newbie
Newbie


Joined: 16 Feb 2007
Online Status: Offline
Posts: 30
Quote TokyoAnt Replybullet Topic: Nulls
    Posted: 10 Apr 2007 at 2:49am
Hi,
 
I have a report that represents an average in the details.
 
If a certain condition is met, I'd like replace the value of the field with NULL in order for the average to be correct. (i.e. If I simply make the value Zero, this will give an incorrect average.)
 
How can I represent a NULL?
 
Thanks for your ideas in advance.
 
Ant
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Apr 2007 at 10:49am
Actually, it won't work with a null.  However, you can do it with 3 formulas.
 
If (condition) then {table.field} else 0
 
{@Count where Condition is met}
If (condition) then 1 else 0
 
{@Average where Condition is Met}
if sum({@Count where Condition is met}, {group field}) > 0 then
  sum({@Number To Average}, {group field})/ Sum({@Count where Condition is met}, {group field})
else
0
 
You'll only put the last formula on your report - it's the average you're looking for.  If you're using it as a grand total and not a group total, take out ", {group field}" from the sums.
 
This process gets the numbers from just the records that match your condition (first formula) and provides a means of counting just the records that match your condition (second formula).  You can then use those numbers to calculate the average (third formula).
 
-Dell
IP IP Logged
TokyoAnt
Newbie
Newbie


Joined: 16 Feb 2007
Online Status: Offline
Posts: 30
Quote TokyoAnt Replybullet Posted: 16 Apr 2007 at 12:52am
Hi Hilfy,
 
Aas always, thanks for your input. I applied the formula's & they work fine.
 
I have another question though. Is it possible to keep the value of the field displayed but have its value suppressed in the totals sums?
 
Thanks very much for your help on this.
 
Ant 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 16 Apr 2007 at 6:54am
Yes - you just put the field with the value in it on the report, but you use something like the {@Number To Average} formula from above to do your calculations.  Formulas used by other formulas do not have to actually be displayed on the report. 
 
-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.