Forum Discussion

admin_xlsior's avatar
admin_xlsior
Icon for Post Prodigy rankPost Prodigy
5 years ago
Solved

Bar chart color based on Field value formula

Hi,

In bar chart, for its Data color property, there is a formula for the Default color.

and inside we can choose a measure by select Field value ->

I tried and succeed to create measure with only like this :

Bar color = "#000000", and select that measure in that property Field Value.

 

My question is can we create more formula, based on the data it self ?

For example, my bar chart, the Axis is actually have values like "10", "20", "30"... it's a status code, and this Axis category of "status code" will be the bar/column of the chart. Can in the formula color, I also specify for example, if "10" then red (#FF0000"), "20" then green ("#00FF00") and so on ?

 

So the end result like :

 

 

I tried with Switch but returns display error.

 

PS: I can set the color individually in the property, but it will only display the "status" (column) that have value, so not fixed. Will be better if using formula.

 

Thanks,

 

 

 

  • Hey admin_xlsior ,

     

    that's absolutely possible.

    Try something similar to that one:

    Bar color =
    SWITCH(
        TRUE(),
        MAX(myTable[Category]) = 10, "#FF0000",
        MAX(myTable[Category]) = 20, "##00FF00",
        "#000000"
    )

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution βœ”οΈ and give it a thumbs up πŸ‘
     
    Best regards
    Denis
     

3 Replies

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey admin_xlsior ,

     

    that's absolutely possible.

    Try something similar to that one:

    Bar color =
    SWITCH(
        TRUE(),
        MAX(myTable[Category]) = 10, "#FF0000",
        MAX(myTable[Category]) = 20, "##00FF00",
        "#000000"
    )

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution βœ”οΈ and give it a thumbs up πŸ‘
     
    Best regards
    Denis
     
    • admin_xlsior's avatar
      admin_xlsior
      Icon for Post Prodigy rankPost Prodigy

      Thanks, 

      It works!.

      The error I did then is because I didn't mentioned the column name.

       

      Thanks again.

      • selimovd's avatar
        selimovd
        Icon for Most Valuable Professional rankMost Valuable Professional

        Hey admin_xlsior ,

         

        I'm happy it works now!

        Yes, if you don't mention the table and column name the engine thinks it's a measure.

        In general best practice is to always write table[column] if it's a column and [measure] without the table name if it's a measure. This makes it easy to read.

         

        Best regards

        Denis