BAQ - Calculation on Aggregate Sums

We have a BAQ that Sums the EstProdHrs and ActProdHrs grouped by ResourceID. We would like to then do another calculation (ActProdHrs / EstProdHrs) on those calculated sum fields. I tried doing a top level query with just the subquery table but it is still not able to do the calculation on the sum fields.

I think you have a divide by zero issue. Try this BAQ. I replaced 0s with 1 to let the formula work.
resgrps.baq (18.1 KB)

in general, you should always use a case statement to test for the 0 condition of your denominator… then when that’s 0, you can specify the value to use instead…

case
  when EstProdHrs = 0
  then 0
  else ActProdHrs / EstProdHrs
end

I am sure there are other ways but that’s what I do.

1 Like

That worked. When I originally thought about that, there were rows that did not have a 0 in the denominator that was still not calculating.