I have been trying to use the colour by expression feature to set the colours in a bar chart to either Red, Amber or Green depending on the values of the data.
In my source data, I have created a field named 'Internal RAG Rating' which contains values Red, Amber or Green (calculated field based on certain criteria). My bar chart uses the Internal RAG Rating as a measure, and count(Internal RAG rating) as a dimension so I have a simple bar chart with 3 columns showing numbers of Red, Amber and Green data items.
I want to set the colours of the individual bars to match the data type, and I have tried using colour by expression but I am failing miserably to define the expression correctly, even for just 2 colours!
I have tried If([Internal RAG rating] = Red, rgb(255,0,0), (If([Internal RAG rating] = Amber,rgb(255,128,0),rgb(0,255,0)),rgb(0,255,0))
and variations on that, but I keep getting the 'Error in Expression' message, even when I try a simple 2 colour option like If([Internal RAG Rating] = Red,rgb(255,0,0),rgb(0,255,0)) it is ignoring the red data and just returning the default colour.
Can someone more technically gifted than me please advise what I am doing wrong and how to code this expression correctly?
=If([Internal RAG rating] = 'Red', rgb(255,0,0),
If([Internal RAG rating] = 'Amber', rgb(255,128,0),
PS: You need to use ' ...' when you use a text value.
you need to add single quotes as below:
If(Internal_RAG_rating = 'Red', RGB(255,0,00),
Tried that but just getting the default colour of Green. Could this be a data problem as the colours are based on an Excel formula?
in your post you use e.g. [Internal RAG rating] .
replace Internal_RAG_rating by [Internal RAG rating] and try again.