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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
CrystalC
New Member

Conditional Formatting broken by Custom Sort

Hi all,

I was able to create a custom (non-alphabetic) sort order for column headers and rows, and I also want to apply conditional formatting to color-code the 1st and 2nd ranking values across a row (Excel mockup to illustrate desired behavior).

 

The DAX below works as a value to conditional format by, but when I apply the custom sort order on rows and columns, the color-coding breaks and everything becomes green.  

 

CrystalC_0-1667682953899.png

 

CF Rank =
VAR cellRank = RANKX(ALLSELECTED(Mockup[Carrier]),
    CALCULATE(SUM(Mockup[Sched Dprts])),,DESC)
RETURN
    SWITCH(TRUE(),
        cellRank = 1,"Green",
        cellRank = 2,"Yellow")
 

Do I need to do a custom sort within the DAX expression...use a SELECTEDVALUE to get at the intersected cell in the matrix? Any suggestions greatly appreciated as I'm a relative newbie.

 

Thanks - Crystal

1 ACCEPTED SOLUTION
v-jialluo-msft
Community Support
Community Support

Hi @CrystalC ,

 

Please follow these steps:

(1) My test data:

vjialluomsft_3-1667809913992.png

 

(2) Add a new measure

CF Rank =

VAR _max =

    CALCULATE (

        MAX ( 'Mockup'[Sched Dprts] ),

        ALLEXCEPT ( Mockup, 'Mockup'[Carrier] )

    )

VAR _nextmax =

    CALCULATE (

        MAX ( 'Mockup'[Sched Dprts] ),

        FILTER ( ALL ( Mockup ), [Sched Dprts] < _max )

    )

RETURN

    SWITCH ( SUM ( Mockup[Sched Dprts] ), _max, "Green", _nextmax, "Yellow" )

 

(3) The result is as follows :

vjialluomsft_4-1667809913994.png

vjialluomsft_5-1667809913998.png

 

Best Regards,

Gallen Luo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jialluo-msft
Community Support
Community Support

Hi @CrystalC ,

 

Please follow these steps:

(1) My test data:

vjialluomsft_3-1667809913992.png

 

(2) Add a new measure

CF Rank =

VAR _max =

    CALCULATE (

        MAX ( 'Mockup'[Sched Dprts] ),

        ALLEXCEPT ( Mockup, 'Mockup'[Carrier] )

    )

VAR _nextmax =

    CALCULATE (

        MAX ( 'Mockup'[Sched Dprts] ),

        FILTER ( ALL ( Mockup ), [Sched Dprts] < _max )

    )

RETURN

    SWITCH ( SUM ( Mockup[Sched Dprts] ), _max, "Green", _nextmax, "Yellow" )

 

(3) The result is as follows :

vjialluomsft_4-1667809913994.png

vjialluomsft_5-1667809913998.png

 

Best Regards,

Gallen Luo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

daXtreme
Solution Sage
Solution Sage

Not able to troubleshoot as one would need the file with the issue to see what's going on.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but please try the below whether it suits your requirement.

 

CF Rank =
VAR cellRank =
    RANKX (
        ALLSELECTED ( Mockup[Carrier], Mockup[Sorting_column_carrier] ),
        CALCULATE ( SUM ( Mockup[Sched Dprts] ) ),
        ,
        DESC
    )
RETURN
    SWITCH ( TRUE (), cellRank = 1, "Green", cellRank = 2, "Yellow" )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.