我有以下示例数据
Country Case Date Austalia 80 22/01/2020 Austalia 100 23/01/2020 Austalia 1200 25/01/2020 Austalia 1500 27/01/2020 America 22 18/02/2020 America 101 22/02/2020 America 200 23/02/2020 America 2100 28/02/2020 Canada 100 24/02/2020 Canada 1200 12/03/2020 Canada 1500 26/03/2020 Canada 1600 27/03/2020 Germany 99 12/01/2020 Germany 100 18/01/2020 Germany 101 19/01/2020 Germany 102 20/01/2020 France 102 13/03/2020 France 304 16/03/2020 France 504 18/03/2020 France 2455 20/03/2020 France 3455 25/03/2020
我想再增加一列“ Day”,该列的价值基于以下条件。
我的决赛桌应该如下所示
#Country Case Date Day Austalia 80 22/01/2020 null Austalia 100 23/01/2020 0 Austalia 1200 25/01/2020 2 Austalia 1500 27/01/2020 4 America 22 18/02/2020 null America 101 22/02/2020 0 America 200 23/02/2020 1 America 2100 28/02/2020 6 Canada 100 24/02/2020 0 Canada 1200 12/03/2020 17 Canada 1500 26/03/2020 31 Canada 1600 27/03/2020 32 Germany 99 12/01/2020 null Germany 100 18/01/2020 0 Germany 100 19/01/2020 1 Germany 102 20/01/2020 2 France 102 13/03/2020 0 France 304 16/03/2020 3 France 504 18/03/2020 5 France 2455 20/03/2020 7 France 3455 25/03/2020 12
感谢有人帮助创建PowerBI度量或DAX函数。
答案 0 :(得分:1)
以下是我为您设计的一些DAX:
DayFromCaseCount99 =
VAR ZERODATE =
CALCULATE (
MIN ( 'Table'[Date] ),
ALLEXCEPT ( 'Table', 'Table'[Country] ),
'Table'[Case] > 99
)
VAR DAYS =
DATEDIFF ( ZERODATE, CALCULATE ( MAX ( 'Table'[Date] ) ), DAY )
RETURN
IF ( MAX ( 'Table'[Case] ) > 99, days, "n/a" )
首先,我按国家/地区计算最早的日期(案例数超过99)。然后,在过滤器上下文中,计算最大日期之间的天数。最后,我再次仅对Case大于99的行显示结果。
希望有帮助。
答案 1 :(得分:0)
创建一个新列并使用以下DAX代码:
Day =
VAR __country = 'Table'[Country]
VAR __subTable = FILTER( 'Table'; 'Table'[Country] = __country )
VAR __minDate = CALCULATE( MIN( 'Table'[Date] ); __subTable; 'Table'[Value] >= 100 )
VAR __result = DATEDIFF(__minDate; 'Table'[Date]; DAY )
Return IF( 'Table'[Value] < 100; BLANK(); __result )
您应该能够获得下一个结果