简体   繁体   English

在为 power bi 中的标志列创建计算列或度量时需要帮助

[英]Need Help in creating a calculated column or Measure for a Flag Column in power bi

I need help in Creating a Flag column based on the aggregated values of two columns in power bi, similar to group by in sql and Fixed{Columnname:Value} in tableau.我需要根据 power bi 中两列的聚合值创建标志列的帮助,类似于 sql 中的 group by 和 tableau 中的 Fixed{Columnname:Value}。

Amount_rc, Amount_rb are two numeric columns Amount_rc, Amount_rb 是两个数值列

Flag Condition:标志条件:

Flag = 
IF(
    'Table'[rc]<>0 && 'Table'[rb]<>0,
    "rc nd rb",
    IF(
        'Table'[rc]<>0 && 'Table'[rb]=0,
        "rc not rb",
        "rb not rc"
    ) 
)

The above calculation is working at each record level.上述计算适用于每个记录级别。 I want it to work at summarized level as below我希望它在汇总级别上工作,如下所示

在此处输入图像描述

Make a measure (not a calculated column) and wrap the columns with a SUM or MAX aggregate:进行度量(不是计算列)并使用SUMMAX聚合包装列:

Flag = IF(SUM('Table'[rc])<>0 && SUM('Table'[rb])<>0,
    "rc nd rb",
    IF(SUM('Table'[rc])<>0 && SUM('Table'[rb])=0,
        "rc not rb",
        "rb not rc"))

(probably rc column should be rv , considering your screenshot) (可能rc列应该是rv ,考虑到你的截图)

I think you need 3 separate Measure to achieve your required output.我认为您需要 3 个单独的Measure才能实现所需的 output。

Measure-1措施一

rc_new = SUM('Table'[rc])

Measure-2测量-2

rb_new = SUM('Table'[rb])

Measure-3措施3

Flag = 
IF(
    rc_new <> 0 && rb_new <> 0,
    "rc nd rb",
    IF(
        rc_new <> 0 && rb_new = 0,
        "rc not rb",
        "rb not rc"
    ) 
)

Now add them to the table visual instead of adding rc and rb column directly.现在将它们添加到表中,而不是直接添加 rc 和 rb 列。

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

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