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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
aflintdepm
Helper III
Helper III

Conditional Formatting by Field Value for multiple measures

I have 5 measures that all use the same scale for for conditional formatting.

 

The measures are (all %):

  • Submitted in 1 day
  • Completed in 3 days
  • Completed in 5 days
  • Completed in 10 days
  • Completed in 15 days

 

I want to use the same formatting scale for each of these

<80% = Red

80-99% = Yellow

99-100% = Green

 

Is there a way to write a measure that I can use across all of these to get the same formatting?

 

Currently, I have a formatting measure for each one that looks like this

% Completed 10 days Format = SWITCH(
    TRUE(),
    [% Completed in 10 Days]<=0.8, "#FDBAB8",
    [% Completed in 10 Days] >=.99, "#b4e0b2",
    "#f0e199")
 
I just change the reference inside the [ ] to make a new one.  What I would like is 1 rule that would work regardless of the measure name inside the bracket.
 
Thanks for the help

 

7 REPLIES 7
byvind
Regular Visitor

Hello,

 

has this been solved?

The only solution I found was to create a separate measure for each item I wanted to format and then select the specific measure for the specific column that I needed to format.  If you only have a few columns, it's annoying but not prohibitive.  If you have a lot of columns, it will be a beast

marcofalzone
Helper I
Helper I

Hi, I'm investigating exactly the same issue. Only one measure to be used as conditional field for many measures. 
Did you find any solution or workaround in the meanwhile?

thank you.

Marco

Unfortunaely, I've made no headway on this.  I spent about an hour duplicating the measure for each thing I wanted to format.  

Thanks for your feedback; I'm investigating a way to do it through some C# script. Not yet sure if it's possible or not, but I will let you know.

I faced the same issue so I created a Tabular Editor script that creates a new conditional formatting field.

 

This script allows to loop over the selected measures or loop over all the measures in the model, in this latter case, I added a condition on the measure name to only apply the script to meaures with "YOY" in their name.

// Creates a measure used as field value for rule-based conditional formatting for each selected measure
foreach(var m in Selected.Measures) {   // Loop over selected measures
// foreach(var m in model.AllMeasures) {   // Loop over all the measures in the model
    var newMeasureName = "__fontColor_" + m.Name;
    
    // Check if measures already exists + condition on measure name
    if (!Model.Tables["__UI_measures"].Measures.Contains(newMeasureName) && m.Name.Contains("YOY")) {
		// m.Table.AddMeasure(    // Add new measure to the same table
        Model.Tables["__UI_measures"].AddMeasure(     // Add measure in a specific table
            "__fontColor_" + m.Name,    // New measure name pattern based on base measure name
            @"VAR __deltaPlusColor = LOOKUPVALUE(
    Colors[Color],
    Colors[Name],
    ""deltaPlusColor""
)
VAR __deltaMinusColor = LOOKUPVALUE(
    Colors[Color],
    Colors[Name],
    ""deltaMinusColor""
)
VAR __deltaSameColor = LOOKUPVALUE(
    Colors[Color],
    Colors[Name],
    ""deltaZeroColor""
)
RETURN
SWITCH(
    TRUE(),
    " + m.DaxObjectName + @" > 0, __deltaPlusColor,
    " + m.DaxObjectName + @" = 0, __deltaZeroColor,
    " + m.DaxObjectName + @" < 0, __deltaMinusColor
)",
        "Formatting"  // to create the new measure in a specific display folder
        // m.DisplayFolder // to create the new measure in the same display folder
        );
    }
}

 

Here's the DAX code created by this script, you can adapt it to your use case in the script.

fontColor_ADR YOY% = 
VAR __deltaPlusColor = LOOKUPVALUE(
    Colors[Color], 
    Colors[Name], 
    "deltaPlusColor" 
)
VAR __deltaMinusColor = LOOKUPVALUE(
    Colors[Color], 
    Colors[Name], 
    "deltaMinusColor" 
)
VAR __deltaZeroColor = LOOKUPVALUE(
    Colors[Color], 
    Colors[Name], 
    "deltaZeroColor" 
)
RETURN SWITCH(
    TRUE(), 
    [ADR YOY%] > 0, 
    __deltaPlusColor, 
    [ADR YOY%] = 0, 
    __deltaZeroColor, 
    [ADR YOY%] < 0, 
    __deltaMinusColor 
)

 

I'm using LOOKUP to avoid hard coding the colors HEX codes. I set all the colors I needed in a table. Just replace the LOOKUPs with the HEX code if you don't want to create a separate table.

Colors =
UNION(
    ROW("Name", "deltaPlusColor", "Color", "#1856C9"),
    ROW("Name", "deltaMinusColor", "Color", "#B80040"),
    ROW("Name", "deltaZeroColor", "Color", "Black")
)

 

As a side note, I recommend using ChatGPT and Claude to adapt the script to your use case, or for creating a new one from scratch. They are very good at it,  and it's easy to experiment and iterate in Tabular Editor. 😉

 

I hope this helps.

v-jingzhang
Community Support
Community Support

Hi @aflintdepm 

 

I tried to use calculation groups to deal with this but failed sadly. Not sure if this is possible with calculation groups. Or I don't have enough experience to find a workaround. 

 

Best Regards,
Community Support Team _ Jing

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.