【问题标题】:Showing value between 2 dates using measure使用度量显示两个日期之间的值
【发布时间】:2020-12-22 11:13:43
【问题描述】:
我在 Power BI 中有一个如下表,其中只有开始日期和结束日期以及此日期之间的值。
| Start_date |
End_date |
Value |
| 2020-12-01 |
2020-12-03 |
7 |
| 2020-12-04 |
2020-12-17 |
8 |
| 2020-12-18 |
2020-12-21 |
6 |
| 2020-12-22 |
2099-12-31 |
7 |
如何使用度量显示特定日期的值(例如,在 2020-12-20,显示值为 6)?
【问题讨论】:
标签:
powerbi
dax
powerquery
measure
【解决方案1】:
如果您的特定日期在 DateTable 中,则例如:
Measure = calculate( max('Table'[Value]), FILTER(ALL('Table'),
'Table'[Start_date]<= SELECTEDVALUE(DateTable[Date])
&& SELECTEDVALUE(DateTable[Date]) <= 'Table'[End_date] )
)
【解决方案2】:
假设您使用切片器 DimDate[Date] 设置特定日期。
然后你可以这样写你的度量:
Measure =
VAR DateSelected = SELECTEDVALUE ( DimDate[Date] )
RETURN
SUMX (
FILTER (
Table1,
Table1[Start_date] <= DateSelected &&
Table1[End_date] >= DateSelected
),
Table1[Value]
)