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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
sarveshkalyan
Advocate I
Advocate I

Regarding Conditional Formatting across columns (Using RANKX/TOPN or alternatives)

I'm having trouble in color coding the values across different columns,

I have 4 metrics(Metric 1,2,3,4) from four different table(Table 1,2,3,4), a calendar table and another table(Table) with just 1 column Metric that has text names of these metrics, i then use switch case to get the values populated as follows, 

suppose this is the data

Metrics202020212022
Metric 1200300100
Metric 2 500210540
Metric 3300320213
Metric 4100800600

 

I would like to get the result like this, get conditional color across different rows(here, the color intensity is based on the highes to lowest of each metric across the years, ie each row is independant) i believe this is possible through field value in background color > cell elements(and i thought of creating a rank measure to specify the context and i am stuck now)

sarveshkalyan_0-1657208230526.png

 

and this is the DAX i have used so far

Rank =
IF(SELECTEDVALUE(Table[Metrics])="Metric 1",
RANKX(
ALLSELECTED('Table1'[Metric 1]),
DISTINCTCOUNT('Table1'[Metric 1]),
BLANK())
 
and the value i am getting is as follows
Fiscal Year202020212022
MetricsValueRankValue RankValue Rank
Metric 1200130011001
Metric 2 500 210 540 
Metric 3300 320 213 
Metric 4100 800 600 

 

Please let me know if this is possible, i think if i get the rank to work, conditional colors can be easily added.

 

Thanks, 

Sarvesh 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sarveshkalyan  ,

Please update the formula of your measure [Rank] as below and check if you can get the rank values:

Rank =
IF (
    SELECTEDVALUE ( Table[Metrics] ) = "Metric 1",
    RANKX (
        ALLSELECTED ( 'Table1'[Metric 1] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table1'[Metric 1] ) )
    ),
    BLANK ()
)

In addition, you can refer the following links to resolve the problem.

Ranking is not showing correctly on card

 

rank = RANKX(ALL('Table'[Name]),CALCULATE(SUM('Table'[Sales])),,DESC,Dense)

 

Showing Ranking in a Visual in Power BI using RANKX DAX function

yingyinr_1-1657535225826.png

If the above one can't help you get the desired result, please provide some sample data in your tables "Table"and "Table1" (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @sarveshkalyan  ,

Please update the formula of your measure [Rank] as below and check if you can get the rank values:

Rank =
IF (
    SELECTEDVALUE ( Table[Metrics] ) = "Metric 1",
    RANKX (
        ALLSELECTED ( 'Table1'[Metric 1] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table1'[Metric 1] ) )
    ),
    BLANK ()
)

In addition, you can refer the following links to resolve the problem.

Ranking is not showing correctly on card

 

rank = RANKX(ALL('Table'[Name]),CALCULATE(SUM('Table'[Sales])),,DESC,Dense)

 

Showing Ranking in a Visual in Power BI using RANKX DAX function

yingyinr_1-1657535225826.png

If the above one can't help you get the desired result, please provide some sample data in your tables "Table"and "Table1" (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

Best Regards

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors