Creating variables from Group Footer sum

Hi,

I am trying to create variables from a number in a group that would sum numbers conditionally.
For example I have a table with dog breeds and an embedded table with the gender of the dog (male, female). I would like to store the total female and total male numbers in two different variables and display them at the end of the report for all breeds. I have done a SetVar on the field but when I output it at the end with GetVar it is only showing whatever the last number in the last breed from the breed table happened to be.

LL Version 25

Thank you

Hi William,

Indeed this should work with a SetVar function albeit combined with a GetVar. Instead of just using

SetVar("Female", <GroupSumValue>)

you’d use something along the lines of

SetVar("Female", NullSafe(GetVar("Female"),0) + <GroupSumValue>)

That way, you’ll add the new count to the existing one and should get the total for all breeds. Would that work for you?

Thanks for the reply Jochen,

This did not work for me unfortunately, when I implemented this the field I put it in ended up doing a running total of female and male. Is there a way to create a User Variable that adds up the numbers kind of behind the scenes and then I could print the user variable at the end?

I’ve tried to mimic this in our sample application, using a hierarchical data source Categories > Products and within the products a grouping by the “Discontinued” flag. The sample uses a group sum called @ProductCounter. In the group footer, it does (excuse this, it’s really verbose):

"Total Products (running): "+ToString$(Cond(Products.Discontinued, 

/* if product is discontinued, increment the corresponding counter */
SetVar("Discontinued", val(NullSafe(GetVar("Discontinued")))+@ProductCounter), 

/* if product is still available, increment the corresponding counter */
SetVar("Continued", val(NullSafe(GetVar("Continued")))+@ProductCounter) 
))

In other words - depending on the discontinuation flag, increment either the one or the other counter by the amount of products in the current group.

In the footer of the outer table I can then output

"Overall "+ToString$(GetVar("Continued")) +" Products continued, "+ToString$(GetVar("Discontinued"))+ " Products discontinued"

which renders

image

for my data.

I’m attaching the sample, you can open it with the demo application that comes with the product (Design > Reports).

Sample With Group Sums.srt (65.5 KB)