Question

My apologies if this has been answered already; it probably has, but I haven't found it in over an hour of Google and SO searching.

I have a non-additive formula field (Cost / Qty). It works fine on detail rows, but when I add it to my group footers, it returns the values from the last detail row rather than a group-level calculation. What do I need to do to get the formula evaluated upon all the rows in a group? I'm surprised this isn't default behavior when adding a field to a group header or footer.

Here's what I'm getting:

Category    Cost Qty Avg Cost
Detail A-1  $100   1 $   100
Detail A-2  $200   3 $    67
Footer A    $300   4 $    67

I expect to see an Avg Cost of $75 in the footer: $300 / 4. If I used an aggregate I'd get an incorrect value (e.g., $167 for Sum, $83 for Avg). In Cognos, I'd use "Expression" as my aggregation formula.

Can some experienced CR user please tell me what I need to do?

Was it helpful?

Solution

You have to create a new formula field just for the Report Footer.

So if your detail formula is like this:

{Test.Cost} / {Test.Qty}

Then you need to create new formula with the following:

Sum ({Test.Cost}) / Sum ({Test.Qty})

and place it in the Report Footer. This will return the correct average ( 300 / 4 = 75 )

EDIT:

If you want to do this for a Group Footer a similar principle applies. You have to create a new formula field and add it to the Group Footer.

If you were grouping by the Category field for instance then your formula to calculate the average over the group would look like this:

Sum ({Test.Cost}, {Test.Category}) / Sum ({Test.Qty}, {Test.Category})

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top