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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Slabbos
Frequent Visitor

Conditional Formatting in Matrix with Measures Grouped by Columns

Hi All,

 

Hope you can help.

 

I am trying to wrap my head around Conditional formatting using a gradient for a Matrix that has Columns based off Measures.

The gradient conditional formatting is working, but it is ignoring the filter context of the Columns. It is setting the gradient over all values for the Provinces (See Below), I would imagine this is exactly what is needed in most cases. But I am wanting to achieve a gradient conditional formatting per Province for the Inflation Measure.

 

Current Result:

Slabbos_0-1685963103855.png

Expected Result:

Slabbos_1-1685963256290.png

In the expected result, there is a conditional formatting Gradient happening for each Inflation Column By province.

Not sure this is possible to achieve, but your input would be greatly appreciated.

 

Let me know if there is any further info I should supply.

 

Thanks again.

 

 

1 ACCEPTED SOLUTION

Hi , @Slabbos 

If you want to show the two color you can try to add some judgement in dax code , like this:

Measure 2 = 
var _rankx = rankx(ALL('Table'[Brand]),CALCULATE( SUM('Table'[Value])),,DESC,Dense)
var init_color = 0.5
var _end_color =FORMAT( ((1-init_color)/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2) )*_rankx , "0%")
var _end_color2 =FORMAT((COUNTROWS(ALLSELECTED('Table'[Brand]))-_rankx)*(init_color/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2))+init_color,"0%")

return
IF(_rankx< COUNTROWS(ALLSELECTED('Table'[Brand]))/2 , "hsl(80,100%,"&_end_color&")",   "hsl(0,100%,"&_end_color&")")

 

Then we can get this:

vyueyunzhmsft_0-1686121065802.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

5 REPLIES 5
Slabbos
Frequent Visitor

Thank you very much for the reply. Will have a look at your solution and let you know how it goes.

v-yueyunzh-msft
Community Support
Community Support

Hi ,  @Slabbos 

According to your descripition, you want to "Conditional Formatting in Matrix with Measures Grouped by Columns".

I tested it in my side, and the built-in gradient conditional format cannot take effect according to the context. He judges all the fields that are put in.

For your need , you can try to use the dax code to try to realize it .

Here are the steps you can refer to :
(1)This is my test data:

vyueyunzhmsft_3-1686106572297.png

 

(2)Then we can create a measure like this:

Measure = 
var _rankx = rankx(ALL('Table'[Brand]),CALCULATE( SUM('Table'[Value])),,DESC,Dense)
var init_color = 0.5
var _end_color =FORMAT( init_color + (1-init_color)/COUNTROWS(ALLSELECTED('Table'[Brand]))*_rankx,"0%")
return
"hsl(220,100%,"&_end_color&")"

(3)We can configure it in the background color:

The result is as follows:

 

vyueyunzhmsft_4-1686106581608.png

 

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Hi,

 

Thank You, I get the Idea, and I may be able to work with this. But it seems your solution is for 1 colour only. I would like to have it be a gradient from Green(Highest Value) to Red(Lowest Value).

Will play around and let you know if I can figure it out.

Hi , @Slabbos 

If you want to show the two color you can try to add some judgement in dax code , like this:

Measure 2 = 
var _rankx = rankx(ALL('Table'[Brand]),CALCULATE( SUM('Table'[Value])),,DESC,Dense)
var init_color = 0.5
var _end_color =FORMAT( ((1-init_color)/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2) )*_rankx , "0%")
var _end_color2 =FORMAT((COUNTROWS(ALLSELECTED('Table'[Brand]))-_rankx)*(init_color/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2))+init_color,"0%")

return
IF(_rankx< COUNTROWS(ALLSELECTED('Table'[Brand]))/2 , "hsl(80,100%,"&_end_color&")",   "hsl(0,100%,"&_end_color&")")

 

Then we can get this:

vyueyunzhmsft_0-1686121065802.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Hi,

Thank You. That is it. Just 1 Slight change, you didnt use _end_color2. After changing that it works perfectly. Thanks again for your help.

Measure 4 = 
var _rankx = rankx(ALL('Table'[Brand]),CALCULATE( SUM('Table'[Value])),,DESC,Dense)
var init_color = 0.5
var _end_color =FORMAT( ((1-init_color)/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2) )*_rankx , "0%")
var _end_color2 =FORMAT((COUNTROWS(ALLSELECTED('Table'[Brand]))-_rankx)*(init_color/(COUNTROWS(ALLSELECTED('Table'[Brand]))/2))+init_color,"0%")

return
IF(_rankx< COUNTROWS(ALLSELECTED('Table'[Brand]))/2 , "hsl(80,100%,"&_end_color&")",   "hsl(0,100%,"&_end_color2&")")

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors