3 Replies Latest reply: Nov 21, 2017 11:34 AM by Paul M

# Inconsistency with aggregate expression results?

Hi all,

I have an aggregate expression my load script, which follows the basic logic below:

Date

FieldA,

Sum(MetricA) AS MetricA,

Sum(MetricB) AS MetricB,

Sum(MetricA)/Sum(MetricB) AS MetricC

Resident CalculationTable

GROUP BY Date, FieldA

When I put this into a table, I find that MetricC does not equal MetricA/MetricB for about half of the rows. In fact, it is out by a factor of 10. I have been trying to figure this out and I am absolutely stumped. Are we able to use expressions with multiple aggregates as above or should I work around this?

Thanks.

• ###### Re: Inconsistency with aggregate expression results?

Again you need to calculate one more resident because Sum(Sum(Field)) not works even in SQL. You could use one more time

• ###### Re: Inconsistency with aggregate expression results?

First thing I'd check is that the Date column is actually a date (or apply DayName() to it). If the underlying values include timestamps, your grouping will be off even if the end result table only displays the date portion of the stamp.

I'm not aware of any problems with the syntax above - sum(A)/Sum(B) shouldn't be an issue. That said, keep in mind that this will not aggregate to a weighted average in your charts later on - that might be a positive or a negative thing depending on what the metric represents.

Temp:

F1, F2, F3, F4

A, A, 10, 10

A, A, 20, 20

A, A, 15, 30

A, B, 100, 100

A, B, 50, 200

];

Load F1, F2, sum(F3) as MetricA, sum(F4) as MetricB, Sum(F3)/Sum(F4) as MetricC

Resident Temp

GROUP BY F1, F2;

Drop table Temp;

• ###### Re: Inconsistency with aggregate expression results?

Thanks Or. Unfortunately this was my mistake. I was doing another level of aggregation I had forgotten about. Thanks for the response though.