根据最新日期获取数据

时间:2019-02-17 17:44:12

标签: tableau

基于下面的数据集,我试图根据最新的报告日期获得最新的费用。

例如:当报告日期=预测日期(列标题)时,则选择该公式可以达到的报告日期的值

IF [Report Date]=[Forecast Date] THEN [Forecasted Cost] END

但我也想获取截至最新报告日期(即2/15/2019)的后续值。我该如何实现?

期望的输出

+------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
|            | 8/15/2018 | 9/15/2018 | 10/15/2018 | 11/15/2018 | 12/15/2018 | 1/15/2019 | 2/15/2019 | 3/15/2019 | 4/15/2019 | 5/15/2019 | 6/15/2019 | 7/15/2019 | 8/15/2019 |
+------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| Final Cost |  646.00   |  646.00   |  620.00    |  620.00    |  550.00    |  445.00   |  361.00   |  332.50   |  315.40   |  296.40   |  290.70   |  285.00   |  279.30   |
+------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+   

数据集

+------+-------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| Item | Report Date | 8/15/2018 | 9/15/2018 | 10/15/2018 | 11/15/2018 | 12/15/2018 | 1/15/2019 | 2/15/2019 | 3/15/2019 | 4/15/2019 | 5/15/2019 | 6/15/2019 | 7/15/2019 | 8/15/2019 |
+------+-------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| 4124 | 8/15/2018   |  646.00   |  646.00   |  658.00    |  658.00    |  658.00    |  658.00   |  658.00   |           |           |           |           |           |           |
| 4124 | 9/15/2018   |           | 646       | 626        | 626        | 626        | 622       | 622       | 622       |           |           |           |           |           |
| 4124 | 10/15/2018  |           |           | 620        | 620        | 620        | 585       | 585       | 585       | 555       |           |           |           |           |
| 4124 | 11/15/2018  |           |           |            | 620        | 620        | 610       | 595       | 554.5     | 543.38    | 535.35    |           |           |           |
| 4124 | 12/15/2018  |           |           |            |            | 550        | 535       | 505       | 490       | 490       | 490       | 490       |           |           |
| 4124 | 1/15/2019   |           |           |            |            |            | 445       | 430       | 420       | 410       | 400       | 390       |       384 |           |
| 4124 | 2/15/2019   |           |           |            |            |            |           | 361       | 332.5     | 315.4     | 296.4     | 290.7     |       285 | 279.3     |
+------+-------------+-----------+-----------+------------+------------+------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+

1 个答案:

答案 0 :(得分:0)

首先,您需要转置数据集,即具有4列“项目”,“报告日期”,“预测日期”和“预测成本”。然后,创建一个过滤器“预测日期> =报告日期”,并按预测日期显示值。 现在,每个预测日期都有多个值。如果只想获取最新值,则可以使用表计算window_min(date diff)。