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.
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