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
LUCASM
Helper IV
Helper IV

Conditional formatting

I am trying to set a formatting rule where, IF my product value is < the selected product value then Background colour = PINK, if My Product value > the selected product value then Background colour = LIGHT GREEN


I have tried variations of this but on testing I get no result for my item and no formatting happen.


Strangely, even when it does not find my item, testing the calculation it returnes PINK as a value, but this does not show on my matrix as the colour PINK.

 

Conditional Format = 

VAR Selected = MAX('Table'[Value])
VAR My_Product = CALCULATE ( MAX ( 'Table'[Value] ) , 'Table'[Brand] = "My_Brand" )

  RETURN 
    SWITCH(
        TRUE(),
        My_Product < Selected, "Pink",
        My_Product > Selected, "Light Green",
        ""
    )     

 

 

Link to test file 

5 REPLIES 5
LUCASM
Helper IV
Helper IV

@danextian@Jai-Rathinavel 
Thank you for your solutions, I think I have resolved this now using this mod in my code.

VAR My_Product = 
CALCULATE ( 
     MAX ( 'Table'[Value] ), 
     ALL ('Table ),
     'Table'[Brand] = "My_Brand" 
)

Which I believe, removes all filters and then reapplies the brand filter.

Anonymous
Not applicable

Hi,@LUCASM 
We are delighted that you have found a solution and are willing to share it.

 

 If you’re inclined, you might consider accepting this solution, as it could also assist other community members facing the same problem, enabling them to find a resolution more swiftly.

vlinyulumsft_0-1732690120014.png

Thank you for your valuable contribution to the community, and we wish you all the best in your work.

 

Best Regards,

Leroy Lu

Jai-Rathinavel
Super User
Super User

@LUCASM Create a disconnected calculated table with the below dax and pull the brand column in a slicer with single selection and paste the format measure below

 

1. Create a calculated Table ('Brand Slicer') with below dax and pull the column in a slicer

 

Brand Slicer = VALUES(Table[Brand])

 

JaiRathinavel_0-1732621693932.png

 

2. Copy paste below format measure and apply conditional formatting

 

Conditional Format = 
var selected = CALCULATE(SUM(Table[Value]),Table[Brand] = SELECTEDVALUE('Brand Slicer'[Brand]))
var my_product = SUM(Table[Value])
RETURN
SWITCH(TRUE(),
            my_product < selected , "Pink",
            my_product > selected , "Light Green")

 

Did I answer your question ? Please accept this post as a solution.

 

Thanks,

Jai




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





danextian
Super User
Super User

Hi @LUCASM 

 

Looking at your formula, both the selected product value and my_product are coming form the same table so when you select a product value from the slice, my_product also gets filtered to that specific product value.

Things you can do:

  • Change the slicer to a slider and select before - this will include every value up to the max slicer selection
  • Use a disconnected table by getting the distinct rows of 'Table'[Value].  Use this column in the slicer and change the change the Selected variable formula to MAX('Table'[Value])​

 

ValueTable = DISTINCT ( 'Table'[Value]  )

 

Note:  a disconnected table doens't have a relationship to your fact or dimension tables.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Caclulated Tables are not suppoprted in Power BI service.
I had this and I needed to get rid of my Calculated table which is now causing my headache.
Is there no way of ammending the 

VAR My_Product = CALCULATE ( MAX ( 'Table'[Value] ) , 'Table'[Brand] = "My_Brand" )

so it includes all brands and that my Filter then resets it to just my Brand?
I tried using ALL but it doesnt appear to like that either.

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.