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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
steleo
New Member

Conditional formatting with different category

Hello everyone,

 

I have a problem with conditional formatting. 

I would like to apply custom conditional formatting to a stacked column / bar chart that has different categories on the x-axis. Example:

  • If the average of the first category is = 100 then it colors the bar green; if >=50 and <100 then yellow, otherwise red.
  • If the average of the second category is 100=green then t colors the bar green; if >=80 <100 thenn yellow, otherwise red.

Please not: the range changes between the two categories.

It is possible to do that in Power Query or in DAX?

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Since you can use a measure for conditional formatting you can create whatever arbitrary rules you'd like.

 

For example, you could write a measure similar to this

Formatting =
VAR _Cat = SELECTEDVALUE ( Table1[Category] )
VAR _Value = [AvgMeasure]
RETURN
    SWITCH (
        TRUE (),
        _Cat = "Category 1" && _Value = 100,                 1, // Green
        _Cat = "Category 1" && _Value >= 50 && _Value < 100, 2, // Yellow
        _Cat = "Category 1",                                 3, // Red
        _Cat = "Category 2" && _Value = 100,                 1, // Green
        _Cat = "Category 2" && _Value >= 80 && _Value < 100, 2, // Yellow
        _Cat = "Category 2",                                 3, // Red
        4
    )

and then set up your formatting rules like this:

AlexisOlson_0-1665863637255.png

 

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

Since you can use a measure for conditional formatting you can create whatever arbitrary rules you'd like.

 

For example, you could write a measure similar to this

Formatting =
VAR _Cat = SELECTEDVALUE ( Table1[Category] )
VAR _Value = [AvgMeasure]
RETURN
    SWITCH (
        TRUE (),
        _Cat = "Category 1" && _Value = 100,                 1, // Green
        _Cat = "Category 1" && _Value >= 50 && _Value < 100, 2, // Yellow
        _Cat = "Category 1",                                 3, // Red
        _Cat = "Category 2" && _Value = 100,                 1, // Green
        _Cat = "Category 2" && _Value >= 80 && _Value < 100, 2, // Yellow
        _Cat = "Category 2",                                 3, // Red
        4
    )

and then set up your formatting rules like this:

AlexisOlson_0-1665863637255.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.

Top Solution Authors