Forum Discussion
How do I create a Colour Measure for each column?
- 4 years ago
Hi HamidBee ,
According to your latest file, here's my solution.
1.Create the color measure.
Colour = SWITCH ( MAX ( '2021'[Letter] ), "A", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" ), "B", IF ( MAX ( '2021'[Value] ) > 10, "Blue", "Green" ), "C", IF ( MAX ( '2021'[Value] ) > 10, "Red", "Green" ), "D", IF ( MAX ( '2021'[Value] ) > 10, "Orange", "Green" ), "E", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" ) )2.For visual A, put Dates in Axis, Value in Values and put Letter in the vasual filter, then selete Letter is A. For visual B, select Letter is B, and so on.
3.For each visual, use the color measure for data color, get the expected result.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for your reply. Although what I was looking for is a bar chart. Something like this:
So if it is greater than 0 then it would be green and if it is less than 0 then it would bre red. I wanted to create seperate bar charts for each letter. I am trying to do it by creating one calculated measure for all of the bar charts instead of seperate ones. Please find a link to the full question here along with the latest pbix file:
https://community.powerbi.com/t5/Desktop/Colour-DAX-Measures-aren-t-working-as-they-should/m-p/2253432
It seems that what I am trying to do is not possible but if you have figured out a way please let me know.
Thank you
Hi HamidBee ,
According to your latest file, here's my solution.
1.Create the color measure.
Colour =
SWITCH (
MAX ( '2021'[Letter] ),
"A", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" ),
"B", IF ( MAX ( '2021'[Value] ) > 10, "Blue", "Green" ),
"C", IF ( MAX ( '2021'[Value] ) > 10, "Red", "Green" ),
"D", IF ( MAX ( '2021'[Value] ) > 10, "Orange", "Green" ),
"E", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" )
)
2.For visual A, put Dates in Axis, Value in Values and put Letter in the vasual filter, then selete Letter is A. For visual B, select Letter is B, and so on.
3.For each visual, use the color measure for data color, get the expected result.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- HamidBee4 years agoPower Participant
How would I ammend the code if I had measures instead? so for example I have 5 measures which calculate the total of A,B,C,D and E. e.g:
Total A = calculate(sum('2021'[Value]), Filter('2021', '2021'[Letter] ="A"))
How would one ammend your code to include all possibilities for each of the 5 measures.
Colour =
SWITCH (
MAX ( '2021'[Letter] ),
"A", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" ),
"B", IF ( MAX ( '2021'[Value] ) > 10, "Blue", "Green" ),
"C", IF ( MAX ( '2021'[Value] ) > 10, "Red", "Green" ),
"D", IF ( MAX ( '2021'[Value] ) > 10, "Orange", "Green" ),
"E", IF ( MAX ( '2021'[Value] ) > 10, "Purple", "Green" )
)- v-yanjiang-msft4 years agoCommunity Support
Hi HamidBee ,
By my test, if you would like to write seperate measures for letter, you have to write seperate color measures as show in your above thread link. Otherwise, you can use my solution and achieve the same result.
Best Regards,
Community Support Team _ kalyj