如何获取最新日期的值,其中值不为空?
How to get the value at the latest date, where values are not null?
我有一个 table 这样的。注意底部的空白值。
我想获取最新日期的值,但该值不能为空
我的 DAX 公式正在返回最新日期 (19/12/2021
) 的值,即 null
但是我想返回最新的非空值,即日期 21/11/2021
.
这是我目前尝试过的方法:
Latest Value =
CALCULATE(
// get sum of value column
SUM('Table1'[Value]),
// where value is not blank, and date is max date
'Table1'[Value] <> BLANK() && Table1[Date] = MAX(Table1[Date])
)
我认为这应该会带回数字 305?因为我的条件是:
where value is not null AND where date = max date
最大日期现在不应该是 21/11/21
因为空值已被删除?
我尝试过的另一个 DAX,使用 fiter
函数。
Latest Value = CALCULATE(
SUM('Table1'[Value]),
FILTER(ALL('Table1'),
'Table1'[Value] <> BLANK()
&&
'Table1'[Date] = MAX('Table1'[Date]))
我哪里错了?我认为这与我的 max date
部分有关。
不幸的是,所有文件托管商都在工作中被阻止,所以我无法共享这个虚拟文件。
想法是先过滤 table 并从日期列中获取最大值。就我而言,我将该日期保存在变量 last_date 中。然后我们只是 select 使用 last_date.
过滤的值列中的值
LatestValue =
VAR last_date =
CALCULATE ( MAX ( 'Table1'[Date] ), 'Table1'[Value] <> BLANK () )
RETURN
CALCULATE ( SELECTEDVALUE ( 'Table1'[Value] ), 'Table1'[Date] = last_date )
或与 SUM 相同的表达式:
LatestSumOfValues =
VAR last_date = CALCULATE(MAX('Table1'[Date]),'Table1'[Value] <> BLANK())
RETURN
CALCULATE(SUM('Table1'[Value]),'Table1'[Date] = last_date)
我有一个 table 这样的。注意底部的空白值。
我想获取最新日期的值,但该值不能为空
我的 DAX 公式正在返回最新日期 (19/12/2021
) 的值,即 null
但是我想返回最新的非空值,即日期 21/11/2021
.
这是我目前尝试过的方法:
Latest Value =
CALCULATE(
// get sum of value column
SUM('Table1'[Value]),
// where value is not blank, and date is max date
'Table1'[Value] <> BLANK() && Table1[Date] = MAX(Table1[Date])
)
我认为这应该会带回数字 305?因为我的条件是:
where value is not null AND where date = max date
最大日期现在不应该是 21/11/21
因为空值已被删除?
我尝试过的另一个 DAX,使用 fiter
函数。
Latest Value = CALCULATE(
SUM('Table1'[Value]),
FILTER(ALL('Table1'),
'Table1'[Value] <> BLANK()
&&
'Table1'[Date] = MAX('Table1'[Date]))
我哪里错了?我认为这与我的 max date
部分有关。
不幸的是,所有文件托管商都在工作中被阻止,所以我无法共享这个虚拟文件。
想法是先过滤 table 并从日期列中获取最大值。就我而言,我将该日期保存在变量 last_date 中。然后我们只是 select 使用 last_date.
过滤的值列中的值LatestValue =
VAR last_date =
CALCULATE ( MAX ( 'Table1'[Date] ), 'Table1'[Value] <> BLANK () )
RETURN
CALCULATE ( SELECTEDVALUE ( 'Table1'[Value] ), 'Table1'[Date] = last_date )
或与 SUM 相同的表达式:
LatestSumOfValues =
VAR last_date = CALCULATE(MAX('Table1'[Date]),'Table1'[Value] <> BLANK())
RETURN
CALCULATE(SUM('Table1'[Value]),'Table1'[Date] = last_date)