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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Tiphany01
Frequent 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, P1

 

Since there can be scenarios where status and priority are same, then the deciding factor should be Expected sales column (Descending order).

Since there can be scenarios where statuspriority, Expected sales  are same, then Expected forecast should be considered.

 

Sample Table:

Product    StatusPriorityExpected SalesExpected Forecast

AOn-goingP1116199
BOn-goingP444181
COn-goingP451259
DOn-goingP444141
EOn-goingP154143
FOn-goingP2454172
GPreparationP3671111
HPreparationP414772
IPreparationP1553175
JPreparationP24358
KPreparationP360129
LDecideP247628
MDecideP2286115
NDecideP2476102

 

Desired output:

Tiphany01_1-1663169282627.png

 

Aim 1 -- To build a custom rank column which helps in sorting based on the requirement.

Aim 2 -- To build a custom cumulative total of expected sales based on this sorting order.

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Here is one (rather longwinded) way.

1) Create dimension tables with the order you need for Status and Priority

p table.pngstatus.pngmodel.png

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
_Index
Cumulative Sales =
VAR _CurrentRank = [Index]
RETURN
    CALCULATE ( [Sum Expected], FILTER ( ALL ( fTable ), [Index] <= _CurrentRank ) )

To get

result.png

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

4 REPLIES 4
PaulDBrown
Community Champion
Community Champion

What is your measure for [Rank Expected]?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






It should be the combination of status, priority, expected sales and expected forecast. Ranking defined based on the way the data is sorted and then ranking to be provided to them

What I meant is can you post the code for the measure. Also what fields from which tables are you using in the visual? 
if you set up the dimension tables, measures and visual following my example, where are you getting the error?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

Here is one (rather longwinded) way.

1) Create dimension tables with the order you need for Status and Priority

p table.pngstatus.pngmodel.png

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
_Index
Cumulative Sales =
VAR _CurrentRank = [Index]
RETURN
    CALCULATE ( [Sum Expected], FILTER ( ALL ( fTable ), [Index] <= _CurrentRank ) )

To get

result.png

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.