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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote 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
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 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.