简体   繁体   English

Power BI :: 根据另一列更改背景颜色

[英]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:我之前问过一个关于如何使用PREVIOUSMONTH的问题,多亏了我能够创建 2 列:

  • first one with the current month spending per resource on Azure第一个是 Azure 上每个资源的当月支出
  • second one with the same resources on the previous month:上个月具有相同资源的第二个:

在此处输入图像描述

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:像这样:

在此处输入图像描述

I checked into Conditional Formatting > Background Color but I think there is no option for doing that.我检查了条件格式>背景颜色,但我认为没有这样做的选择。

So I created this DAX rule:所以我创建了这个 DAX 规则:

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?现在,如何使用此规则为 SelectedMonth 着色?

Or is there any Visual that could do that out-of-the-box?或者是否有任何视觉效果可以开箱即用?

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.添加如下 3 条规则。

BTW, your measure can and should be simplified using the SWITCH(TRUE()) pattern.顺便说一句,您的措施可以而且应该使用 SWITCH(TRUE()) 模式进行简化。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM