Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field formula: accumulation, VB syntax

Status
Not open for further replies.

revizor

MIS
Jul 17, 2002
4
US
I recently had to manually convert SQL query into Crystal Reports field formula. Since it's my first encounter with CR, I picked VB syntax for the formula.
I know the formula itself is correct. My problem is that I don't know how to accummulate the values returned by the formula for each customer_id - in my report in the detail line I get only the last (or first?) value returned for each individual customer_id, and not the sum for the given customer_id
I know there should be an easy two-step fix, either by redefining variable or by some other trick.
The formula is similar to the one given below, except it's way more twisted.

=== cut ===
Dim x
x= IIf({Table.Field1} + {Table.Field2}=0, {Table.Field3},{Table.Field4})

formula=x
=== cut ===

Please help me figure out how to accumulate values returned for each individual customer_id. Putting sum(...) does not work.
 
Group your report on Customer ID. Place your formula field in a detail section. Right-click on the field and select Summary. Type of summary = Sum, on change of Customer ID.
The sum field will appear in the Customer ID Group Footer.
You can suppress the detail rows if all you want is the sum.

Your formula should work, but I would write it as:
If {Table.Field1} + {Table.Field2}=0 then
formula = {Table.Field3}
else
formula = {Table.Field4}

You don't really need the variable "x" or the "IIF" function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top