简体   繁体   English

我们可以比较 DAX Power BI 中 Switch Case 中的两个表吗?

[英]Can we compare two tables in a Switch Case in DAX Power BI?

Is it possible to include columns from 2 different tables in DAX Switch Function?是否可以在 DAX 交换机 Function 中包含来自 2 个不同表的列?

Both of my tables are linked by Many to Many Relationship.我的两个表都通过多对多关系链接。
I am trying to create a calculated column in Table A where I want to compare Columns from Table B, but I can't add the Table B column in the DAX Switch formula.我正在尝试在表 A 中创建一个计算列,我想在其中比较表 B 中的列,但我无法在 DAX 开关公式中添加表 B 列。
Any suggestions would be appreciated.任何建议,将不胜感激。

Thanks & Regards,感谢和问候,
Pratik普拉提克

Sample样本
Table B表 B
Table A & Expected Result表 A 和预期结果

Instead of trying to use two columns from two different tables for comparison in DAX, you can use the 'RELATED` DAX function to import a column from Table A to Table B or vice-versa.您可以使用“相关”DAX function 将表 A 中的列导入表 B,反之亦然,而不是尝试使用两个不同表中的两列进行比较。 Then you can use this column for comparison in DAX.然后您可以使用此列在 DAX 中进行比较。

Just set the appropriate relationship between Table A and Table B and create a new column with the RELATED DAX function to import the table that you want to use in the SWITCH function.只需在表 A 和表 B 之间设置适当的关系,并使用RELATED DAX function 创建一个新列,以导入要在SWITCH function 中使用的表。

In my opinion, it doesn't matter whether this table has many relationship, the only thing matter is that you are calculated based on your original table instead of calculate on a new measure, then result is unpredictable:在我看来,这张表是否有很多关系并不重要,唯一重要的是您是根据原始表计算而不是根据新度量计算,那么结果是不可预测的:

By create new table from the original table, and add column for the comment, I can provide result as your expectation, hope it solve your problem and accept the answer:)通过从原始表创建新表,并为评论添加列,我可以提供您期望的结果,希望它能解决您的问题并接受答案:)

  1. Create new table from original table (Sheet1 is my old table) and select on ID column从原始表(Sheet1 是我的旧表)和ID列上的 select 创建新表

    Table = SELECTCOLUMNS(Sheet1,"ID",Sheet1[ID])

  2. Create new column for comment为评论创建新列

    Column = SWITCH(LOOKUPVALUE('Sheet1'[Value],Sheet1[ID],'Table'[ID]), 0,"Matched with A","Matched with B")

The outcome for the new table:新表的结果:

在此处输入图像描述

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

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