Print Page | Close Window

Sum of Formula field

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Tips and Tricks
Forum Discription: Have you learned some great tricks to share with the group? Post them here!
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15072
Printed Date: 04 May 2024 at 9:21pm


Topic: Sum of Formula field
Posted By: OlgaS
Subject: Sum of Formula field
Date Posted: 02 Dec 2011 at 7:34am
Hi Experts,
 
I need your help. I have a formula field (@ep),  and i need to calculate a sum of this field: sum(@ep). When i use 'Insert', I do not see formula fields. Field @ep is numeric, not string. What should I do?
 
Thank you



Replies:
Posted By: lockwelle
Date Posted: 06 Dec 2011 at 9:05am
if the formula is calculating something that is not in the raw the data (ie, it is not summing up a field, but is say adding a field conditionally) then you cannot use the built in aggregate functions.
 
you could track the value yourself by adding something like this to the @ep:
shared numbervar rtTotal;
local numbervar thisTotal;
 
if ..... then .....
 
thisTotal := original value of @eps
 
rtTotal := rtTotal + thisTotal;
 
thisTotal   // CR always prints the last value it is given
 
then when you want to display the total, you would create a formula like:
shared numbervar rtTotal;
rtTotal
 
and if the value should ever by reset, then where you want the total to reset you would have something like:
shared numbervar rtTotal := 0;
"" //hides the reset from displaying


Posted By: OlgaS
Date Posted: 07 Dec 2011 at 6:31am
Thank you



Print Page | Close Window