【发布时间】:2021-06-09 08:42:13
【问题描述】:
我在 Power BI 模型中有 2 个表,[日期] 和 [配额]
- “日期”[YYYYMM] 用作报告中的期间过滤器
- 我想根据所选时间段的最大日期显示最新的配额
如何将其写入 DAX / 计算列?
Example:
If I select YYYYMM = "202005" in filter.
Below table should show:
|product|quota|
|A |10 |
|B |20 |
Quota Table:
|product|quota|effectiveDate|
|A |10 |2020-01-01 |
|B |20 |2020-01-01 |
|A |25 |2021-01-01 |
Date Table:
|Date |YYYYMM|
|2020-01-01|202001|
|2020-01-02|202001|
...
|2021-06-09|202106|
要获得最新的配额,在 SQL 中应该是:
SELECT TOP (1) q.Quota
FROM [Quota] q
LEFT JOIN [Date] d on d.[Date] >= q.effectiveDate
ORDER BY q.effectiveDate desc
【问题讨论】: