在一个列中对多个数值进行切片 Power BI

huangapple go评论64阅读模式
英文:

Slicer On Multiple Values In One Column Power BI

问题

我有一个包含许多列的表格,其中之一是一个论坛。以下是各行论坛列中值的示例:

论坛


MD、CIO、CEO、IT


CIO、MD


MD


MD、IT、CFO


CEO


CEO、IT


CEO、CIO


IT


IT、CFO、CEO


CFO


我想要一个包含上述所有可能属性的切片器,看起来像这样:

MD


CEO


CFO


IT


CIO

思路是,如果在切片器中没有选中任何内容,则可视化显示表格中的所有行。但如果在切片器中选择了任何内容,则可视化仅显示具有该属性的行。因此,如果用户选择了“MD”,则仅显示具有以下值的行:

MD、CIO、CEO、IT


MD


MD、IT、CFO

英文:

I have a table that contains many of columns, one of which is a Forum. Here's a sample of the values in the Forum column for various rows:

Forum


MD, CIO, CEO, IT


CIO, MD


MD


MD, IT, CFO


CEO


CEO, IT


CEO, CIO


IT


IT, CFO, CEO


CFO


I want a slicer that contains all of the possible attributes above, so it looks like this:

MD


CEO


CFO


IT


CIO

The idea is that if nothing is selected in the slicer, then the visual shows all rows in the table. But if anything is selected in the slicer, then the visual shows only those rows in which that attribute is present. So, if the user selected "MD", the only rows shown would be those with the following values:

MD, CIO, CEO, IT


MD


MD, IT, CFO

答案1

得分: 1

对于切片器,您需要创建一个包含所有不同值的新表。您可以按照下面的代码生成new_table。假设您当前的表名为"your_table_name"。

let
    Source = your_table_name,
    #"按分隔符拆分列" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Forum", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Forum"),
    #"更改类型" = Table.TransformColumnTypes(#"按分隔符拆分列",{{"Forum", type text}}),
    #"修剪文本" = Table.TransformColumns(#"更改类型",{{"Forum", Text.Trim, type text}}),
    #"删除重复项" = Table.Distinct(#"修剪文本")
in
    #"删除重复项"

现在创建下面的Measure-

check_ = 
VAR _selected = SELECTEDVALUE ( new_table[Forum])
RETURN
IF (
    CONTAINSSTRING ( SELECTEDVALUE (your_table_name[Forum] ), _selected )
        || ISBLANK(_selected),
    1,
    0
)

现在,在表可视化中,将新创建的度量添加到筛选部分,如下所示-

在一个列中对多个数值进行切片 Power BI

最终输出将如下所示-

在一个列中对多个数值进行切片 Power BI

英文:

For the slicer, you need to create a new table with all distinct values. You can follow this below code to generate the new_table. Assuming your current table name is "your_table_name"

let
    Source = your_table_name,
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Forum", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Forum"),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Forum", type text}}),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Forum", Text.Trim, type text}}),
    #"Removed Duplicates" = Table.Distinct(#"Trimmed Text")
in
    #"Removed Duplicates"

now create this below Measure-

check_ = 
VAR _selected = SELECTEDVALUE ( new_table[Forum])
RETURN
IF (
    CONTAINSSTRING ( SELECTEDVALUE (your_table_name[Forum] ), _selected )
        || ISBLANK(_selected),
    1,
    0
)

Now, in the table visual, add the newly created measure in the filter section as below-

在一个列中对多个数值进行切片 Power BI

The final output will be like-

在一个列中对多个数值进行切片 Power BI

答案2

得分: 0

创建以下的度量:

=
VAR SelectedForums =
    VALUES( ForumList[Forum] )
RETURN
    IF(
        HASONEVALUE( ForumList[Forum] ),
        IF(
            COUNTROWS( FILTER( Table1, SEARCH( SelectedForums, Table1[Forum],, 0 ) ) ),
            1,
            0
        ),
        1
    )

然后,您可以将它拖放到您所需的可视化/页面的“筛选器”窗格中,并设置条件为等于1。

英文:

Create the following measure:

=
VAR SelectedForums =
    VALUES( ForumList[Forum] )
RETURN
    IF(
        HASONEVALUE( ForumList[Forum] ),
        IF(
            COUNTROWS( FILTER( Table1, SEARCH( SelectedForums, Table1[Forum],, 0 ) ) ),
            1,
            0
        ),
        1
    )

which you can then drag into the Filters Pane for your desired visuals/pages and set the condition that it be equal to 1.

huangapple
  • 本文由 发表于 2023年5月29日 15:04:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定