Forum Discussion

TuckRhodes's avatar
TuckRhodes
Helper I
3 years ago

Clustered Bar Chart Functional Bar Coloring

Hello all!

 

I have a clustered bar chart with this year sales and last year sales as the bars. I want to have this years bar be colored red or green depending on if sales for that category exceeds that of last year. Is this possible

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  TuckRhodes ,

    I created some data:

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    var _lastyear=
    SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(TODAY())-1),[Amount])
    var _currentyear=
    SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(TODAY())),[Amount])
    return
    SWITCH(
        TRUE(),
        YEAR(MAX('Table'[Date]))=YEAR(TODAY())&&_currentyear > _lastyear,"red",
        YEAR(MAX('Table'[Date]))=YEAR(TODAY())&&_currentyear <= _lastyear,"green",
        "blue")

    2. Format – Bars – Colors -- fx.

    3. Enter the Default color interface.

    4. Result:

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • TuckRhodes's avatar
      TuckRhodes
      Helper I


      Hello Liu!

       

      Thanks for taking the time to provide an answer. Unfortunately, this isn't quite the scenario I was trying to describe. My sitiuation is better depicted by the above photo. Along the Y axis I have category of sales (as the main purpose of the page is to break down sales by category) and along the X axis is sales amount. Each category has two bars depending on what year it was sold but the bars come in pairs for each category just as in the image above the letters at the bottom have two bars each. So, to try and rephrase more appropriately, would there be a way to change the color of the orange(ish) bar to red or green contingent upon whether or not it is greater than the darker colored bar in each category?