如何在 DAX 中从我的 table 的某些条件下从另一个 table 获取记录?
How can I bring a record from another table with certain conditions from my table in DAX?
我有两个 table。一份提供技术支持的日期和客户 ID [Table 1],另一份提供发送给客户的调查 [Table 2])。问题是调查是在服务完成几天后发送的。因此,我需要从调查 table 中找到最接近日期的调查 ID,并将其带给我的技术支持 table。这是我的数据样本和想要的结果。
Table1:
TechSupportDate CustomerID
01/12/2018 1
02/12/2018 2
05/12/2018 1
Table2:
SurveyID SurveyDate CustomerID
1001 04/12/2018 1
1002 04/12/2018 2
1003 10/12/2018 1
预期结果:
TechSupportDate CustomerID SurveyDate SurveyID
01/12/2018 1 04/12/2018 1001
02/12/2018 2 04/12/2018 1002
05/12/2018 1 10/12/2018 1003
向表 1 添加计算列:
SurveyDate =
CALCULATE (
MIN ( Table2[SurveyDate] ),
FILTER (
Table2,
Table2[SurveyDate] >= Table1[TechSupportDate] && Table2[CustomerID] = Table1[CustomerID]
)
)
和
SurveyID =
CALCULATE (
FIRSTNONBLANK ( Table2[SurveyID], 1 ),
FILTER (
Table2,
Table2[SurveyDate] = Table1[SurveyDate] && Table2[CustomerID] = Table1[CustomerID]
)
)
这是一个 PBIX 的工作示例:https://excel.solutions/so_54693431/
我有两个 table。一份提供技术支持的日期和客户 ID [Table 1],另一份提供发送给客户的调查 [Table 2])。问题是调查是在服务完成几天后发送的。因此,我需要从调查 table 中找到最接近日期的调查 ID,并将其带给我的技术支持 table。这是我的数据样本和想要的结果。
Table1:
TechSupportDate CustomerID
01/12/2018 1
02/12/2018 2
05/12/2018 1
Table2:
SurveyID SurveyDate CustomerID
1001 04/12/2018 1
1002 04/12/2018 2
1003 10/12/2018 1
预期结果:
TechSupportDate CustomerID SurveyDate SurveyID
01/12/2018 1 04/12/2018 1001
02/12/2018 2 04/12/2018 1002
05/12/2018 1 10/12/2018 1003
向表 1 添加计算列:
SurveyDate =
CALCULATE (
MIN ( Table2[SurveyDate] ),
FILTER (
Table2,
Table2[SurveyDate] >= Table1[TechSupportDate] && Table2[CustomerID] = Table1[CustomerID]
)
)
和
SurveyID =
CALCULATE (
FIRSTNONBLANK ( Table2[SurveyID], 1 ),
FILTER (
Table2,
Table2[SurveyDate] = Table1[SurveyDate] && Table2[CustomerID] = Table1[CustomerID]
)
)
这是一个 PBIX 的工作示例:https://excel.solutions/so_54693431/