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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

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

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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