Forum Discussion
Ranking with multiple rows and drilldown
- 2 years ago
Hi again VBLOT
Thanks so much for the file! That made it a lot easier to debug.
It seems that the problem actually relates to how the visual level filter "Sum of Nb samples collected > 0" interacts with the ALLSELECTED () modifier used to produce the table for ranking.
A safer way to write the measure is below (see attached PBIX). Actually in their Whitepaper, SQLBI recommend this general approach of adding column(s) to the "relation" argument of window functions.
I might have to get back to you with an explanation of why it works when I've analyzed further.
Rank FIX = VAR IsLineInScope = ISINSCOPE ( 'Invoices List'[Line Designation] ) VAR IsREFInScope = ISINSCOPE ( 'Invoices List'[REF] ) VAR Result = SWITCH ( TRUE ( ), IsLineInScope && IsREFInScope, RANK ( DENSE, CALCULATETABLE ( ADDCOLUMNS ( SUMMARIZE ( 'Invoices List', 'Invoices List'[Line Designation], 'Invoices List'[REF] ), "@TotalSamples", [Total Samples collected] ), ALLSELECTED () ), ORDERBY ( [@TotalSamples], DESC ), , PARTITIONBY('Invoices List'[REF]) ), NOT IsLineInScope && IsREFInScope, RANK ( DENSE, CALCULATETABLE ( ADDCOLUMNS ( SUMMARIZE ( 'Invoices List', 'Invoices List'[REF] ), "@TotalSamples", [Total Samples collected] ), ALLSELECTED ( ) ), ORDERBY ( [@TotalSamples], DESC ) ) ) RETURN ResultRegards
Hi again OwenAuger,
Please find a sanitised file here :
https://norishare.com/P9TDkeS9yJF
Thanks for your help.
Hi again VBLOT
Thanks so much for the file! That made it a lot easier to debug.
It seems that the problem actually relates to how the visual level filter "Sum of Nb samples collected > 0" interacts with the ALLSELECTED () modifier used to produce the table for ranking.
A safer way to write the measure is below (see attached PBIX). Actually in their Whitepaper, SQLBI recommend this general approach of adding column(s) to the "relation" argument of window functions.
I might have to get back to you with an explanation of why it works when I've analyzed further.
Rank FIX =
VAR IsLineInScope = ISINSCOPE ( 'Invoices List'[Line Designation] )
VAR IsREFInScope = ISINSCOPE ( 'Invoices List'[REF] )
VAR Result =
SWITCH (
TRUE ( ),
IsLineInScope && IsREFInScope,
RANK (
DENSE,
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE (
'Invoices List',
'Invoices List'[Line Designation],
'Invoices List'[REF]
),
"@TotalSamples", [Total Samples collected]
),
ALLSELECTED ()
),
ORDERBY ( [@TotalSamples], DESC ), ,
PARTITIONBY('Invoices List'[REF])
),
NOT IsLineInScope && IsREFInScope,
RANK (
DENSE,
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE ( 'Invoices List', 'Invoices List'[REF] ),
"@TotalSamples", [Total Samples collected]
),
ALLSELECTED ( )
),
ORDERBY ( [@TotalSamples], DESC )
)
)
RETURN
Result
Regards