Forum Discussion

Ania26's avatar
Ania26
Helper IV
1 year ago
Solved

Conditional formatting Data bars based on the other field

Hello, I have a Total Sales= 100 and in those 100, 50 is Shoes, 20 is Clothes and 30 is Other. How can I color bars using conditional formatting,  that it shows Total Sales=100% fully colored , then ...
  • danextian's avatar
    1 year ago

    Hi Ania26 

    First, does your data include a row for Total Sales? If not, you'll need to create a disconnected table. It's also unclear what you want to happen with the remaining part of the bar. Should it be colored in a lighter shade? If yes, you’ll need two separate measures - one for the main color and one for the lighter fill. If not, a single measure will be enough.

    Disconnected Table - 

    CategoryWithTotal = 
    VAR _total =
        ROW ( "Category", "Total", "Sort", BLANK () )
    VAR _category =
        SUMMARIZECOLUMNS ( 'Table'[Category], "Sort", 1 )
    RETURN
        UNION ( _total, _category )
    

     

    Measure -

    Sales with Total = 
    IF (
        SELECTEDVALUE ( CategoryWithTotal[Category] ) = "Total",
        SUM ( 'Table'[Sales] ),
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            TREATAS ( VALUES ( CategoryWithTotal[Category] ), 'Table'[Category] )
        )
    )
    

    Note: I'm confident my reponse is not an untested AI-generated one 🙂

     

    Please see the attached pbix.