Custom Rollup Without a Hierarchy

We had a scenario where the user want to see average at the ROW level and the SUM of the averages at the TOTAL level in a matrix. There was no hierarchy on the rows. The rows have the 'Financial Summary Line Type'[Digital Description] column.

Here's the brute force solution:

LineType gets the value of  the 'Financial Summary Line Type'[Digital Description] column for the DETAIL rows and BLANK() for the TOTAL row.


Average Sales (Digital Rollup) =

VAR LineType = SELECTEDVALUE('Financial Summary Line Type'[Digital Description], BLANK())
VAR AllDigitalLineTypes =
ADDCOLUMNS(
CALCULATETABLE(
VALUES('Financial Summary Line Type'[Digital Description]),
'Financial Summary Line Type'[Digital] = 1
),
"@AverageSales", CALCULATE(DIVIDE(SUM('Financial Summary'[TransactionAmount]), COUNTROWS('Calendar')))
)

RETURN

IF (
NOT ISBLANK(LineType),
DIVIDE(SUM('Financial Summary'[TransactionAmount]), COUNTROWS('Calendar')),
SUMX(AllDigitalLineTypes, [@AverageSales])
)

Comments

Popular posts from this blog

Difference between DISTINCT and VALUES in DAX