Forum Discussion
Display Ranked Totals
- 9 years ago
Looks like I've found a way to do this.
I'll post just in case someone can think of a more straight forward way or has the same problem.
in a nutshell, I calculate the table using summarize, filter this down and then perform the ranking and summing of sales using add columns.
I wrap this all in a SUMX to interate through values and return the result.
testtableoutput :=
VAR SelectedNo =
IF (
ISFILTERED ( 'TopN Options'[TopN] ),
VALUES ( 'TopN Options'[TopN] ),
BLANK ()
)
VAR fTable =
IF (
ISBLANK ( SelectedNo ),
CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
SUMX (
FILTER (
ADDCOLUMNS (
SUMMARIZE ( ALLSELECTED ( Office ), Office[DWHId], Office[Location Title] ),
"MyValue", CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
"MyRank", RANKX (
ALLSELECTED ( Office ),
CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
,
DESC,
DENSE
)
),
[MyRank] <= SelectedNo
),
[MyValue]
)
)
RETURN
fTable
Looks like I've found a way to do this.
I'll post just in case someone can think of a more straight forward way or has the same problem.
in a nutshell, I calculate the table using summarize, filter this down and then perform the ranking and summing of sales using add columns.
I wrap this all in a SUMX to interate through values and return the result.
testtableoutput :=
VAR SelectedNo =
IF (
ISFILTERED ( 'TopN Options'[TopN] ),
VALUES ( 'TopN Options'[TopN] ),
BLANK ()
)
VAR fTable =
IF (
ISBLANK ( SelectedNo ),
CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
SUMX (
FILTER (
ADDCOLUMNS (
SUMMARIZE ( ALLSELECTED ( Office ), Office[DWHId], Office[Location Title] ),
"MyValue", CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
"MyRank", RANKX (
ALLSELECTED ( Office ),
CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
,
DESC,
DENSE
)
),
[MyRank] <= SelectedNo
),
[MyValue]
)
)
RETURN
fTable