Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Evan0211
Creator
Creator

Measure sum showing in KPI

I have a measure that has the following expression:

=If((TYPE = '1' and IsNull(ORDER))
or (TYPE = '2' and Not IsNull(ORDER))
or (TYPE = '1')
,
sum( aggr(only(Num([Ceiling], '$#,##0.00')), [ID]))


if((TYPE = '2' and IsNull(ORDER)),
sum( aggr(only(Num([VALUE], '$#,##0.00')), [ID]))
)
)

 

When used as a measure in a table and using a sum, this calculates correctly at the top of the table.  Now I need to show that value in a KPI.  I tried wrapping the expression in a Sum() but there is nested aggregation and I am not sure how to get around that.  Is there a way to see the expression for the built in Sum at the top of the table?

Labels (1)
1 Solution

Accepted Solutions
Or
MVP
MVP

This will not sum correctly as-is because in the context of a total, e.g. Type=1 will not be true (there are multiple types, so Type is not equal to 1). Ideally, you should refactor this expression so that it can work correctly within both row and totals context by moving the if() logic inside the sum / aggr contexts, e.g.

sum( aggr(only(if((TYPE = '2' and IsNull(ORDER)),Num([VALUE],num([Ceiling])) '$#,##0.00')), [ID]))

Note, I probably didn't get that quite right since it's copy pasted,  but the idea is to have the logic inside the aggregation rather than vice versa. This will result in the if() logic being evaluated for each row before it is aggregated.

You could probably make this work as-is by wrapping the whole thing in a sum(aggr(YourBigExpressionHere,YourDimension1,YourDimension2,etc)) as well, but that approach is potentially inefficient, limited to fixed dimensions, and is not the "correct" way of writing an expression.

View solution in original post

2 Replies
Or
MVP
MVP

This will not sum correctly as-is because in the context of a total, e.g. Type=1 will not be true (there are multiple types, so Type is not equal to 1). Ideally, you should refactor this expression so that it can work correctly within both row and totals context by moving the if() logic inside the sum / aggr contexts, e.g.

sum( aggr(only(if((TYPE = '2' and IsNull(ORDER)),Num([VALUE],num([Ceiling])) '$#,##0.00')), [ID]))

Note, I probably didn't get that quite right since it's copy pasted,  but the idea is to have the logic inside the aggregation rather than vice versa. This will result in the if() logic being evaluated for each row before it is aggregated.

You could probably make this work as-is by wrapping the whole thing in a sum(aggr(YourBigExpressionHere,YourDimension1,YourDimension2,etc)) as well, but that approach is potentially inefficient, limited to fixed dimensions, and is not the "correct" way of writing an expression.

Evan0211
Creator
Creator
Author

This is expressing to 0.00 instead of the summation of the measure (column).

EDIT: I had a missing ) that was throwing everything off.  Your solution worked  thanks!