Error "Cannot mix aggregate and non-aggregate arguments with this function" When Creating a Calculated Field
"Cannot mix aggregate and non-aggregate arguments with this function."
The issue can be resolved through one of the below options:
Option 1 (Aggregate Then Divide)
Wrap all fields in an aggregation.Sample:
[Profit] / SUM ([Sales]) -> SUM ([Profit]) / SUM ([Sales])
Option 2 ( Divide Then Aggregate)
Remove aggregations from all of the fields.Sample:
[Profit] / SUM ([Sales]) ->[Profit] / [Sales]
Option 3 ( Condition Then Aggregate)
Move the aggregation so all fields are aggregated.For example, the calculation:
IF [Row ID] = 1
THEN SUM( [Sales] )
END
could become:THEN SUM( [Sales] )
END
SUM(
IF [Row ID] = 1
THEN [Sales]
END )
IF [Row ID] = 1
THEN [Sales]
END )
OR Do like this:
COUNT(IF MONTH([Submitted Date])=MONTH(TODAY())
then
[Incident Number]
END)
The above will calculate the count of [Incident Number] for the current month
Option 4 (Convert to Non-Aggregate Then Aggregate)
Use a Level of Detail (LOD) Expression to make an aggregation non-aggregate. All LOD expression return non-aggregated values.[Sales]/SUM( [Sales] ) -> [Sales]/{FIXED: SUM( [Sales] )}
Cause
Aggregations are computed at the level of detail in the view, which will return one value for several records. Non-aggregate fields are computed for every record in the underlying data, which will return one value per record.Tableau Desktop would not know how to compare the one value of the aggregation to the several values of the non-aggregated field.
Additional Information
Imported fields and Level of Detail (LOD) expressions are always non-aggregated until they are wrapped in an aggregation, such as SUM(), MIN(), ATTR(), etc... Calculated fields can be either aggregate or non-aggregate depending on how aggregations are used. If no aggregations are used, or if the outer most expression is a LOD expression, then the calculation will return non-aggregated results.Below is an explanation of how each option works using the sample data set shown as a reference.
Sample Data Set
ROW ID | PROFIT | SALES |
---|---|---|
1 | 100 | 30 |
2 | 50 | 60 |
3 | 7 | 10 |
Option 1
SUM ([Profit]) / SUM ([Sales])Result:
(100 + 50 + 7) / (30 + 60 + 10) = 157/100 = 1.57
Option 2
[Profit] / [Sales]Result: (assuming that the aggregation in the view is SUM)
100/30 + 50/60 + 7/10 = 3.333 + .833 + .7 = 4.867
Option 3
Result:30 + 0 + 0 = 30
Option 4
See Level of Details Calculations
Level of Detail expressions always return non-aggregate results and can be used to specify the level the aggregation occurs at.
[Sales]/{FIXED: SUM( [Sales] )}
Result: (assuming that the aggregation is sum)
30/100 + 60/100 + 10/100 = 3+60+10 = .3 + .6 + .1 = 1
Comments
Post a Comment