简体   繁体   English

在 power bi dax 中使用 OR 切换为真

[英]SWITCH TRUE WITH OR in power bi dax

I have 15 columns in a power bi table.我在 power bi 表中有 15 列。 I would like to create new measure that will return the column names if the percentage value of any columns is less than 60%.如果任何列的百分比值小于 60%,我想创建将返回列名的新度量。

Example table:示例表:

ID ID total全部的 col2 col2 col3 col3 col4 col4 col5 col5
a100 100 50 50 35 35 10 10 5 5 6 6
a101 a101 36 36 25 25 5 5 12 12 18 18

I created a new measure for each column that shows the percentage我为显示百分比的每一列创建了一个新度量

%col2 = SUM(col2)/SUM(total)*100
%col3 = SUM(col3)/SUM(total)*100
%col4 = SUM(col4)/SUM(total)*100
%col5 = SUM(col5)/SUM(total)*100

By the new measure above, I will get col2 >60%通过上面的新措施,我会得到 col2 >60%

What I would like is to create a visual, maybe by kpi or a table that will return only the columns that have less than 60%.我想要的是创建一个视觉效果,可能是通过 kpi 或一个只返回小于 60% 的列的表。

I tried the following:我尝试了以下方法:

col_to_improv = SWITCH(TRUE(), OR(table[col2] < 60, "columnname", table[col3] < 60, "col_name2", table[col4] < 60, "col_name3"), table[col5] < 60, "col_name4],"")

I would like to show only the column names that has less than 60%, otherwise, do not show.我只想显示小于 60% 的列名,否则不显示。

From the above example table, In the kpi (or other visual), I am expecting only col3,col4, and col5, because they have less than 60%.从上面的示例表中,在 kpi(或其他视觉)中,我只期望 col3、col4 和 col5,因为它们的比例不到 60%。

I would advice you to transpose your table (if it's able) because it's easier to work with values than column names.我建议您转置表格(如果可以的话),因为使用值比使用列名更容易。

在此处输入图像描述 Don't forget to add to your table one row with metrics description (Column1 in my example)不要忘记在表格中添加一行带有指标描述(在我的示例中为 Column1)

If you do so you with get desired result with pretty easy DAX measure:如果您这样做,您可以通过非常简单的 DAX 测量获得所需的结果:

col_to_improv =
SWITCH(
    TRUE,
    SELECTEDVALUE('Table'[Column2]) < 60,
    SELECTEDVALUE('Table'[Column1])
)

在此处输入图像描述

Column names - [Table Name],[Column Name] comes from COLUMNSTATISTICS(), so, don't change them, the rest you can name according to your model列名 - [Table Name],[Column Name] 来自 COLUMNSTATISTICS(),所以,不要改变它们,其余的你可以根据你的模型命名

VAR myTableStat=
        Filter(
            COLUMNSTATISTICS()
            ,[Table Name]="MyTable"
        )
        
VAR withSUM=
       ADDCOLUMNS(
            myTableStat
            ,"colSum",
                      SWITCH(
                               [Column Name]
                               ,"col2",SUM(MyTable[col2])
                               ,"col3",SUM(MyTable[col3])
                               ,"col4",SUM(MyTable[col4])
                               ,"col5",SUM(MyTable[col5])
                       )

                         
        )
VAR totalSum= SUM(MyTable[total])
VAR  withAveLessThen60 =
        FILTER(
            withSUM
            ,AND(
                DIVIDE(
                        [colSum]
                        ,totalSum
                )<0.6
                ,NOT ISBLANK([colSum])
            )
        )
            
VAR result = 
    CONCATENATEX(
                withAveLessThen60
                ,IF(
                    NOT ISBLANK([colSum])
                    ,[Column Name]                  
                )
                ,"; "
                
    )
        
RETURN 
      result

在此处输入图像描述

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

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