DAX- 列查找
DAX- Column look up
我有一个 table 列 End_Of_Month,ID.
我想要实现的目标:我想知道哪些 ID 在 2021 年 3 月 31 日 没有 发生在下一个month_end_date.
举个例子:31/3/2021提到的2个ID(ID 3 & ID 4)没有出现在下一个日历中month_end_date。
我假设您想针对每个 End_Of_Month
值显示一个度量。
结果是缺失的 ID
的串联,用逗号分隔。
计算:测量
MissingIds =
VAR CurrentMonth =
SELECTEDVALUE ( 'Table'[End_Of_Month] )
VAR NextMth =
EOMONTH ( CurrentMonth, 1 )
VAR AllIds =
SUMMARIZE ( FILTER ( ALL ( 'Table' ), [End_Of_Month] = NextMth ), [ID] )
VAR CurrentIds =
VALUES ( 'Table'[ID] )
VAR MissingIds =
EXCEPT ( CurrentIds, AllIds )
VAR Result =
CONCATENATEX ( MissingIds, [ID], "," )
RETURN
IF ( ISEMPTY ( AllIds ), BLANK (), Result )
输出
Table
End_Of_Month
ID
31 March 2021
1
30 April 2021
1
31 May 2021
1
31 March 2021
2
30 April 2021
2
31 May 2021
2
31 March 2021
3
31 May 2021
3
31 May 2021
3
31 March 2021
4
30 April 2021
7
30 April 2021
8
30 April 2021
9
编辑:
我修改了计算以考虑任何日期,而不是月末 (EOM)。
请参阅下面的 table 作为参考。
MissingIds =
VAR CurrentDate =
SELECTEDVALUE ( 'Table'[Date] )
VAR NextDt =
MINX ( FILTER ( ALL ( 'Table' ), [Date] > CurrentDate ), [Date] )
VAR AllIds =
SUMMARIZE ( FILTER ( ALL ( 'Table' ), [Date] = NextDt ), [ID] )
VAR CurrentIds =
VALUES ( 'Table'[ID] )
VAR MissingIds =
EXCEPT ( CurrentIds, AllIds )
VAR Result =
CONCATENATEX ( MissingIds, [ID], "," )
RETURN
IF ( ISEMPTY ( AllIds ), BLANK (), Result )
输出
Table
Date
ID
15 January 2021
1
15 January 2021
2
15 January 2021
3
18 January 2021
2
18 January 2021
2
18 January 2021
5
22 January 2021
7
22 January 2021
7
22 January 2021
5
此解决方案适用于数据到下个月月底的情况,但对于数据到月中的情况,它给出 0。如何解决?
举个例子:
我希望计算也显示 4 月 30 日至 5 月 14 日期间缺少的 ID。
我有一个 table 列 End_Of_Month,ID.
我想要实现的目标:我想知道哪些 ID 在 2021 年 3 月 31 日 没有 发生在下一个month_end_date.
举个例子:31/3/2021提到的2个ID(ID 3 & ID 4)没有出现在下一个日历中month_end_date。
我假设您想针对每个 End_Of_Month
值显示一个度量。
结果是缺失的 ID
的串联,用逗号分隔。
计算:测量
MissingIds =
VAR CurrentMonth =
SELECTEDVALUE ( 'Table'[End_Of_Month] )
VAR NextMth =
EOMONTH ( CurrentMonth, 1 )
VAR AllIds =
SUMMARIZE ( FILTER ( ALL ( 'Table' ), [End_Of_Month] = NextMth ), [ID] )
VAR CurrentIds =
VALUES ( 'Table'[ID] )
VAR MissingIds =
EXCEPT ( CurrentIds, AllIds )
VAR Result =
CONCATENATEX ( MissingIds, [ID], "," )
RETURN
IF ( ISEMPTY ( AllIds ), BLANK (), Result )
输出
Table
End_Of_Month | ID |
---|---|
31 March 2021 | 1 |
30 April 2021 | 1 |
31 May 2021 | 1 |
31 March 2021 | 2 |
30 April 2021 | 2 |
31 May 2021 | 2 |
31 March 2021 | 3 |
31 May 2021 | 3 |
31 May 2021 | 3 |
31 March 2021 | 4 |
30 April 2021 | 7 |
30 April 2021 | 8 |
30 April 2021 | 9 |
编辑:
我修改了计算以考虑任何日期,而不是月末 (EOM)。 请参阅下面的 table 作为参考。
MissingIds =
VAR CurrentDate =
SELECTEDVALUE ( 'Table'[Date] )
VAR NextDt =
MINX ( FILTER ( ALL ( 'Table' ), [Date] > CurrentDate ), [Date] )
VAR AllIds =
SUMMARIZE ( FILTER ( ALL ( 'Table' ), [Date] = NextDt ), [ID] )
VAR CurrentIds =
VALUES ( 'Table'[ID] )
VAR MissingIds =
EXCEPT ( CurrentIds, AllIds )
VAR Result =
CONCATENATEX ( MissingIds, [ID], "," )
RETURN
IF ( ISEMPTY ( AllIds ), BLANK (), Result )
输出
Table
Date | ID |
---|---|
15 January 2021 | 1 |
15 January 2021 | 2 |
15 January 2021 | 3 |
18 January 2021 | 2 |
18 January 2021 | 2 |
18 January 2021 | 5 |
22 January 2021 | 7 |
22 January 2021 | 7 |
22 January 2021 | 5 |
此解决方案适用于数据到下个月月底的情况,但对于数据到月中的情况,它给出 0。如何解决?
举个例子:
我希望计算也显示 4 月 30 日至 5 月 14 日期间缺少的 ID。