Forum Discussion

Roinka's avatar
Roinka
Helper I
7 years ago
Solved

Conditional bar color

Hi, I have a bar chart which displays a list of categories and number of points in each category. One of the categories is a control category. I would like the chart to show all categories above t...
  • OwenAuger's avatar
    7 years ago

    Hi Roinka

     

    You will have to create some sort of measure that determines whether the sum of Points is greater than or less than the Control Category, and use that as the basis for conditional formatting.

     

    Here is an example

     

    In this example I created these measures:

    Points Sum = 
    SUM ( Points[Points] )
    
    Points Sum Control Category = 
    CALCULATE ( 
        [Points Sum],
        Points[Category] = "Control Category"
    )
    
    Bar Colour = 
        IF (
            SELECTEDVALUE ( Points[Category] ) = "Control Category",
            "green",
            VAR PointsSumRelativeToControl = 
                SIGN ( [Points Sum] - [Points Sum Control Category] )
            RETURN
                SWITCH (
                    PointsSumRelativeToControl,
                    1,"blue",
                    0,"grey", // Grey for categories that happen to have points equal to control
                    -1,"red"
                )
        )

    In this example, the Bar Colour measure itself returns the name of the colour, so is used under Data colors => Conditional formatting => Field Value.

     

    You should be able to adapt this to your needs.

     

    Regards,

    Owen