cancel
Showing results for 
Search instead for 
Did you mean: 

Best practice for creating a sum of a formula?

Former Member
0 Kudos

What is the best way to create a sum on multiple groups from a formula or another sum?

Sum ({IC_ADJS_JNL.QTY}, {IC_ITEM_MST.ALT_ITEMB}) * {NT_CONV_FCT.NET} - This is sitting in GF1, but I also need the sum of this on GF2.

{NT_USED_DEM.USAGE_QTY} - {@RPK_LBS} - another example sitting in GF1 but needs its sum in GF2

Hopefully I have explained this well enough. Thanks in advance for your help!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

In order to answer this question correctly, you'll need to tell us what fields group 1 and group 2 are based on, and what the formula for {@RPK_LBS} is (really, only if it uses SUM() or some other aggregate).

For the first formula, the group 2 version would probably be something like


Sum ({IC_ADJS_JNL.QTY}, {group 2 field}) * {NT_CONV_FCT.NET}

HTH,

Carl

Former Member
0 Kudos

Group #1 is Whse_code

#2 is IC_ITEM_MST.ALT_ITEMB

@RPK_LBS is.....Sum ({IC_ADJS_JNL.QTY}, {IC_ITEM_MST.ALT_ITEMB}) * {NT_CONV_FCT.NET}

Should I just make a formula for each field at each group level? or is it better to try and create a sql Expression and attempt to sum off of that?

Former Member
0 Kudos

I usually create a separate formula field for each grouping level - the primary reason being is it is easier for someone (else) to modify or debug.

Shouldn't the formulas you posted be in GF2 instead of GF1?

HTH,

Carl

Former Member
0 Kudos

Yes your correct. I will just make seperate formulas then. I just wasnt sure if that was the best way to do it. Thanks for your help.

Answers (1)

Answers (1)

Former Member
0 Kudos

You can create make use of global variable, the logic is similar to running total.

What you do is:

1. You initialize a global variable.

Whileprintingrecords

numbervar gcount::=0;

2. You accumulate the variable at the section you want.

Whileprintingrecords;

numbervar gcount;

gcount:=gcount + xxxx

If you need certain condition, just use if statment like normal.

3. To display the global varaible

Whileprintingrecords;

numbervar gcount;