0

我有下表,我正在尝试根据最新日期提取状态

--------------------------------------
   Date    | User |  Status  | ID |
--------------------------------------
12-01-2019 |  A   | Approved | 1A |
14-01-2019 |  A   | Approved | 1A |    
21-02-2019 |  B   | Rejected | 2B |
26-02-2019 |  B   | Approved | 2B |
--------------------------------------

我使用了以下 DAX

Max_date = Calculate(max(table1[Date]),(ALLEXCEPT(table1,table1[User],table1[ID]))

Result = Calculate(max(table1[Status]), FILTER(ALLEXCEPT(table1,table1[User],table1[ID]),
                   table1[Date]= table1[Max_date]))

这给了我以下结果

---------------------------------------------------------
   Date    | User |  Status  | ID | Max_Date  | Result  |
---------------------------------------------------------
12-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved |
14-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved |
21-02-2019 |  B   | Rejected | 2B |26-02-2019 |Approved |
26-02-2019 |  B   | Approved | 2B |26-02-2019 |Approved |
----------------------------------------------------------

我的表2,

------------------------------
| ID    |  Car     | Type    |
------------------------------
|  1A   | Benz     | A-class |
|  1B   | Benz     | B-class |    
|  1C   | Benz     | C-class |
|  1B   | BMW      | M1      |  
|  2B   | BMW      | M2      |
------------------------------

我已经定义了与 table1 和 table2 的关系。[将 ID 映射到两个表中的 ID] 当我将 Car 和 Type 添加到表中时,数据会膨胀(类似于交叉连接)。

--------------------------------------------------------------------------
   Date    | User |  Status  | ID | Max_Date  | Result  | Car  | Type    |
--------------------------------------------------------------------------
12-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | Benz | A-Class |
14-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | Benz | A-Class |
21-02-2019 |  B   | Rejected | 2B |26-02-2019 |Approved | Benz | B-Class |
26-02-2019 |  B   | Approved | 2B |26-02-2019 |Approved | Benz | B-Class |
12-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | BMW  | M1      |
14-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | BMW  | M2      |
21-02-2019 |  B   | Rejected | 2B |26-02-2019 |Approved | BMW  | M1      |
26-02-2019 |  B   | Approved | 2B |26-02-2019 |Approved | BMW  | M2      |
--------------------------------------------------------------------------

我想要的输出,


   Date    | User |  Status  | ID | Max_Date  | Result  | Car  | Type    |
--------------------------------------------------------------------------
12-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | Benz | A-Class |
14-01-2019 |  A   | Approved | 1A |14-01-2019 |Approved | Benz | A-Class |
21-02-2019 |  B   | Rejected | 2B |26-02-2019 |Approved | BMW  | M1      |
26-02-2019 |  B   | Approved | 2B |26-02-2019 |Approved | BMW  | M2      |

4

1 回答 1

0

您可以使用度量来计算您需要什么:

Last Date = CALCULATE(LASTDATE(myTable[Date]), ALL(myTable[Date],myTable[Status]))

Last Status = LOOKUPVALUE(myTable[Status], myTable[Date], [Last Date])

注意:如果您有日历表,请使用日历的日期列。

于 2020-02-06T09:36:28.957 回答