Forum Discussion
Conditional formatting of measures
Hey Trescher ,
I did go down a rabbit hole for this. Well after some hours wasted because I thought oh well what a simple requirement. Anyway, calculation groups cannot do the magic nor can the measure approach with SELECTEDMEASURE (at least not in the ways I tried them). The cleanest solution I could come up with, still requires two measures), was to create an UDF (you will have to enable it in preview features) which goes something like this:
DEFINE FUNCTION GetColor = ( value: NUMERIC ) => IF(value > 0, "#00B050", "#FF0000")
EVALUATE { GetColor(100) }
Run this and upload from the DAX query view.
Then writing the Color measure for your actual measure becomes a breeze. You will be simply writing the coloring measure as follows:
Sales Color = GetColor([Sales])
Profit Color = GetColor([Profit])
Hope it helps!
Hi alish_b ,
Sales Color = GetColor([Sales])
Profit Color = GetColor([Profit])
Would i have to make a coloring measure for all measures that follow this formatting? Or can I reference it in the coloring value function?
- alish_b8 months ago
Super User
Hey Trescher ,
Sadly, you will have to create separate coloring measures for all measures of your interest.
The good news is that the function will centralize the logic, so if the common logic for the coloring were ever to be changed, you would not go about changing each coloring measure logic rather just update the logic in the function. And while, you will still need to make one coloring measure for one measure, the definitions become simpler as it is basic function call on the measure of interest.
- Trescher8 months agoFrequent Visitor
Thanks for the swift reply alish_b !
OK that is definitely some benefit as opposed to defining separate measures in which the logic resides.
Still for me it seems very inefficient to make N seperate measures for these coloring formatting given N measures. Basically it scales with 1-to-1 with every measure that follows this logic.
- Trescher8 months agoFrequent Visitor
Btw i get the following error, some syntax related issue.
- alish_b8 months ago
Super User
Oh my bad! Used a reserved word in there. Try this:
DEFINE FUNCTION GetColor = ( measurevalue: NUMERIC ) => IF(measurevalue > 0, "#00B050", "#FF0000")EVALUATE { GetColor(100) }