简体   繁体   English

Power BI DAX:基于变量筛选器的两个表之间的交叉连接

[英]Power BI DAX : CROSS JOIN between two tables based on a variable filter

I have two input tables in my Power BI model.我的 Power BI model 中有两个输入表。

  1. UserPermission用户权限
  2. Lookup Table查找表

The above two tables are not related.以上两个表相关。

UserPermission:用户权限:

在此处输入图像描述

'All' corresponds to all the segments in the Lookup Table, ie X,Y,Z. “All”对应于查找表中的所有段,即X、Y、Z。

Lookup Table:查找表:

在此处输入图像描述

UserPermission[SgmtID] is equivalent to LookupTable[SegmentID]. UserPermission[SgmtID] 等价于 LookupTable[SegmentID]。

I need to develop an output table, by CROSS JOINing the UserName column in the UserPermission table, and the Ports column in the Lookup Table.我需要开发一个 output 表,通过交叉连接 UserPermission 表中的 UserName 列和查找表中的 Ports 列。

Desired Output table:所需的 Output 表:

在此处输入图像描述

David needs to have all the ports of all the segments in the lookup table (ie X,Y,Z). David 需要在查找表中拥有所有的所有端口(即 X、Y、Z)。

John needs to have all the ports of segment X only. John 只需要拥有段 X的所有端口。

Mike needs to have all the ports of segment Y only. Mike 只需要拥有段 Y的所有端口。

Jill needs to have all the ports of segments X and Z only. Jill 只需要拥有段 X 和 Z的所有端口。

The difference between David and Jill is that David can access all segments, while Jill can access multiple segments, but not all segments. David 和 Jill 的区别在于,David 可以访问所有段,而 Jill 可以访问多个段,但不能访问所有段。

The output table is needed for Row Level Security (RLS).行级安全 (RLS) 需要 output 表。

I know to use CROSS JOIN using VALUES, also some variables and filters.我知道使用 VALUES 使用 CROSS JOIN,还有一些变量和过滤器。 But not able to develop a full DAX query, due to lack of expertise.但由于缺乏专业知识,无法开发完整的 DAX 查询。

Can anyone kindly help me with this?任何人都可以帮我解决这个问题吗?

I think the SUMMARIZECOLUMNS function is probably the easiest one to achieve this with if you need to do this in DAX.如果您需要在 DAX 中执行此操作,我认为SUMMARIZECOLUMNS function可能是最容易实现此目的的方法。

Output Table =
FILTER (
    SUMMARIZECOLUMNS (
        UserPermission[UserName],
        LookupTable[Ports],
        LookupTable[SegmentID],
        "SID", VALUES ( UserPermission[SegmentID] )
    ),
    [SID] < 0 || [SID] = [SegmentID]
)

Recommended reading on this powerful function:推荐阅读这款强大的 function:

https://www.sqlbi.com/articles/introducing-summarizecolumns/https://www.sqlbi.com/articles/introducing-summarizecolumns/


Edit: If you rename UserPermissions[SegmentID] to UserPermissions[SgmtID] so that there aren't two columns of the same name when summarizing, then you can write the combined table as follows and avoid the issue you mentioned in the comments:编辑:如果您将UserPermissions[SegmentID]重命名为UserPermissions[SgmtID]以便在汇总时没有两列同名,那么您可以按如下方式编写组合表并避免您在评论中提到的问题:

Output Table =
FILTER (
    SUMMARIZECOLUMNS (
        UserPermission[UserName],
        UserPermission[SgmtID],
        LookupTable[Ports],
        LookupTable[SegmentID]
    ),
    [SgmtID] < 0 || [SegmentID] = [SgmtID]
)

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

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