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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LamSar
Helper III
Helper III

Dynamic gradient color scale - Power BI Matrix

Good morning,

 

I have a specific requirement:

In a Power BI Matrix I need to add a dynamic gradient color scale based on the min and the max sales per Chain & MarginType. 

 

I've managed to create a gradient color scale, based on the min and max sales for all shops, however, I need to have the min and max values per cluster of Chain and Margin Type.

I've used this measure to achieve this:

var a = maxx(ALLSELECTED(Shop[ShopName]),[_Sales])
var b = MINX(ALLSELECTED(Shop[ShopName]),[_Sales])
var range = a-b
var hue = ROUND(
    DIVIDE([_Sales] - b, range)*120, 0)
var color = "hsla(" & hue & ", " & "100%" & ", " & "90%" & ", " & 1 & ")"
return
color
 
For examle:
ShopSales
A

10

B

20

C

30

D

40

 

Shop A and D are the sames chain and MarginType. Min = 10, max = 40

Shop B and C are the same chain and MarginType. Min = 20, max = 30

 

The Matrix contains the shopName in the rows and sales in the values. On the values I need to apply conditional formatting.  

It doesn't matter if only a few shops are selected or all. The color scale should always be the same. 

In this case I would need 2 color scales because I have 2 different clusters. 

So based on the example the coloring should look like this:

LamSar_0-1693472060576.png

Is something like this even possible?

1 REPLY 1
lbendlin
Super User
Super User

yes, background color is controllable via functions.  You can create another measure that computes the desired color for each of your matrix value cells, and use that measure as the driver for the backgroud color.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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