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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
nmyre
Helper III
Helper III

Creating Conditional color format based on a changing measure

Hello again,

 

I am trying to change the background color of a measure column based on how close it is to a different, calculated measure that changes daily.

 

TSL% or Straight-Line : The percentage measure that is being refferenced as the target.

%Obs or O: The percentage measure that is being color formated based on its proximity to TSL%

I want it to look like this:

0.png

Here is my input.

If O is less than TSL%-.05(so minus 5%) then red, else if O is greater than TSL-.05 and less than TSL+.05 then yellow, else if O is greater than or equal to TSL%+.05 then Green

0.png

This gives me an output of:

new.jpg

I have also been looking at using "color based off calculation" at the bottom of this link but am having issues there too.

 

Any help, helps. Thanks

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@nmyre - First, I would write your measure like this:

 

Color =
  VAR O = [%Ob]
  VAR TSL = [TSL%]
RETURN
  SWITCH(TRUE(),
    O <= TSL - .05,1,
    O > TSL - .05 && O < TSL +.05,2,
    O <=TSL + .05,3,
    4
  )

 

 

 

Then you would do this:

image.png

I attached an example PBIX below sig. Page 8, Table 8.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@nmyre - Yes, so in the example I attached, my "Color" measure was called "Measure 5". I set the conditional formatting on "Measure 3", using "Measure 5" as the basis for my rules.

 

So, in your case, you want to click the down arrow in the Visuals area not on %ObC but on your other measure, %Ob, which you want the color on and choose Conditional Formatting | Background Color. Then choose Rules. Then choose your Color measure and then setup your rules. 

 

Hope that clears things up.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@nmyre - First, I would write your measure like this:

 

Color =
  VAR O = [%Ob]
  VAR TSL = [TSL%]
RETURN
  SWITCH(TRUE(),
    O <= TSL - .05,1,
    O > TSL - .05 && O < TSL +.05,2,
    O <=TSL + .05,3,
    4
  )

 

 

 

Then you would do this:

image.png

I attached an example PBIX below sig. Page 8, Table 8.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

Thank you for your response. I am close but not quite there. I feel as if I am missing something simple. Here is my Measure:

0.png

Here is my output:

0.png

The colors are correct for the adjacent value, but what I am looking for is the percentages inside the color cells. Example:

0.png

 

Any Ideas?

@nmyre - Yes, so in the example I attached, my "Color" measure was called "Measure 5". I set the conditional formatting on "Measure 3", using "Measure 5" as the basis for my rules.

 

So, in your case, you want to click the down arrow in the Visuals area not on %ObC but on your other measure, %Ob, which you want the color on and choose Conditional Formatting | Background Color. Then choose Rules. Then choose your Color measure and then setup your rules. 

 

Hope that clears things up.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

And there it is! Very Good. Thank you.

@nmyre - Awesome! Yeah it's all easy once you know the trick!! But getting there is not necessarily super intuitive! 🙂



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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