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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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