从多个表中获取不同项目的 DAX 查询
DAX Query to Get Distinct Items from Multiple Tables
问题
我正在尝试从多个来源 table 生成 table 个不同的电子邮件地址。但是,在语句外部使用 UNION
语句,它不会生成真正不同的列表。
代码
Participants = UNION(DISTINCT('Registrations'[Email Address]), DISTINCT( 'EnteredTickets'[Email]))
*请注意,虽然我一开始只有两个来源 tables,但我需要在结束时将其扩展到 3 或 4 个。
在 table 选择上使用 VALUES
的组合加上将整个语句包装在另一个语句中 DISTINCT
成功了:
Participants = DISTINCT(UNION(VALUES('Registrations'[Email Address]), VALUES( 'EnteredTickets'[Email])))
如果您想要一个对所有不同的 table 具有唯一值的桥 table,请使用 DISTINCT
而不是 VALUES
:
Participants =
FILTER (
DISTINCT (
UNION (
TOPN ( 0, ROW ("NiceEmail", "asdf") ), -- adds zero rows table with nice new column name
DISTINCT ( 'Registrations'[Email Address] ),
DISTINCT ( 'EnteredTickets'[Email] )
)
),
[NiceEmail] <> BLANK () -- removes all blank emails
)
DISTINCT
AND VALUES
可能会导致不同的结果。本质上,使用 VALUES
,您可能会在列表中得到(不需要的)空白值。
检查此文档:
https://docs.microsoft.com/en-us/dax/values-function-dax#related-functions
您可能还喜欢此 link 下的信息,您可以使用这些信息为您的 table 不同值获取特定列名称:
问题
我正在尝试从多个来源 table 生成 table 个不同的电子邮件地址。但是,在语句外部使用 UNION
语句,它不会生成真正不同的列表。
代码
Participants = UNION(DISTINCT('Registrations'[Email Address]), DISTINCT( 'EnteredTickets'[Email]))
*请注意,虽然我一开始只有两个来源 tables,但我需要在结束时将其扩展到 3 或 4 个。
在 table 选择上使用 VALUES
的组合加上将整个语句包装在另一个语句中 DISTINCT
成功了:
Participants = DISTINCT(UNION(VALUES('Registrations'[Email Address]), VALUES( 'EnteredTickets'[Email])))
如果您想要一个对所有不同的 table 具有唯一值的桥 table,请使用 DISTINCT
而不是 VALUES
:
Participants =
FILTER (
DISTINCT (
UNION (
TOPN ( 0, ROW ("NiceEmail", "asdf") ), -- adds zero rows table with nice new column name
DISTINCT ( 'Registrations'[Email Address] ),
DISTINCT ( 'EnteredTickets'[Email] )
)
),
[NiceEmail] <> BLANK () -- removes all blank emails
)
DISTINCT
AND VALUES
可能会导致不同的结果。本质上,使用 VALUES
,您可能会在列表中得到(不需要的)空白值。
检查此文档:
https://docs.microsoft.com/en-us/dax/values-function-dax#related-functions
您可能还喜欢此 link 下的信息,您可以使用这些信息为您的 table 不同值获取特定列名称: