Search code examples
powerbidaxpowerbi-desktoppowerbi-custom-visuals

Power BI :: change background color based on another column


I previously asked a question about how to use PREVIOUSMONTH and thanks to that I was able to create 2 columns:

  • first one with the current month spending per resource on Azure
  • second one with the same resources on the previous month:

enter image description here

I now would like to change the background color so the number could be:

  • **Red ** if the cost has increased
  • **Green ** if the cost has decreased
  • **Yellow ** if the price is the same

Like this:

enter image description here

I checked into Conditional Formatting > Background Color but I think there is no option for doing that.

So I created this DAX rule:

PreviousMonthCheck = 
IF ([PreviousMonth] < MAX('Usage details'[costInBillingCurrency]),1,
    IF ([PreviousMonth] = MAX('Usage details'[costInBillingCurrency]),2,
        IF ([PreviousMonth] > MAX('Usage details'[costInBillingCurrency]),3,
            "Fourth case"
        )
    )
)

Now, how to use this rule to color the SelectedMonth?

Or is there any Visual that could do that out-of-the-box?


Solution

  • For this, you can do it with native visuals. In the custom formatting, choose Rules and then reference your measure. Add the 3 rules as below.

    BTW, your measure can and should be simplified using the SWITCH(TRUE()) pattern.

    enter image description here