Forum Discussion
Tiphany01
3 years agoFrequent Visitor
Multiple columns custom sort with Rank column
Dears, I have a table below which needs to be sorted in a particular manner: 1) Status column order should be -> on-going, Preparation, Decide 2) Priority column order should be -> P4, P3, P2, ...
- 3 years ago
Here is one (rather longwinded) way.
1) Create dimension tables with the order you need for Status and Priority
Next the following measures:
Sum Expected = SUM('fTable'[Expected])Sum Forecast = SUM(fTable[Forecast])an index to sort the expected/forecats rank and the corresponding rank measure:
Value for Rank = [Sum Expected] * 100000000000 + [Sum Forecast]Rank Expected = IF ( ISBLANK ( [Sum Expected] ), BLANK (), RANKX ( ALLEXCEPT ( fTable, 'Status Table'[Status], 'Priority Table'[Priority] ), [Value for Rank] ) )The final Index to use in the final rank to get the cumulative sales
Index = VAR _Status = MAX('Status Table'[Order]) * 1000000000000000 VAR _Priority = MAX('Priority Table'[Order]) * 10000000000000 VAR _Expected = [Rank Expected] * 10000000 VAR _Forecast = [Sum Forecast] VAR _Index = IF(AND(ISBLANK([Sum Expected]), ISBLANK([Sum Forecast])), BLANK(), _Status + _Priority + _Expected + _Forecast) RETURN _IndexCumulative Sales = VAR _CurrentRank = [Index] RETURN CALCULATE ( [Sum Expected], FILTER ( ALL ( fTable ), [Index] <= _CurrentRank ) )To get
I've attached the sample PBIX file
PaulDBrown
3 years agoCommunity Champion
Here is one (rather longwinded) way.
1) Create dimension tables with the order you need for Status and Priority
Next the following measures:
Sum Expected = SUM('fTable'[Expected])Sum Forecast = SUM(fTable[Forecast])
an index to sort the expected/forecats rank and the corresponding rank measure:
Value for Rank = [Sum Expected] * 100000000000 + [Sum Forecast]Rank Expected =
IF (
ISBLANK ( [Sum Expected] ),
BLANK (),
RANKX (
ALLEXCEPT ( fTable, 'Status Table'[Status], 'Priority Table'[Priority] ),
[Value for Rank]
)
)
The final Index to use in the final rank to get the cumulative sales
Index =
VAR _Status = MAX('Status Table'[Order]) * 1000000000000000
VAR _Priority = MAX('Priority Table'[Order]) * 10000000000000
VAR _Expected = [Rank Expected] * 10000000
VAR _Forecast = [Sum Forecast]
VAR _Index = IF(AND(ISBLANK([Sum Expected]), ISBLANK([Sum Forecast])), BLANK(), _Status + _Priority + _Expected + _Forecast)
RETURN
_IndexCumulative Sales =
VAR _CurrentRank = [Index]
RETURN
CALCULATE ( [Sum Expected], FILTER ( ALL ( fTable ), [Index] <= _CurrentRank ) )
To get
I've attached the sample PBIX file