如何根据分组条件创建列?

How to create a column based on grouped condition?

我在 powerbi 中的测试表:

IdRecord Date Value
1 2022-04-25 23:45:00.000 100
1 2022-04-24 18:07:00.000 344
2 2022-05-01 23:45:00.000 5
2 2022-05-02 18:07:00.000 66
2 2022-05-03 18:07:00.000 31

我需要创建一个计算列来标记最早的按 id 分组的记录。

期望的输出

IdRecord Date Value IsFirst
1 2022-04-25 23:45:00.000 100 0
1 2022-04-24 18:07:00.000 344 1
2 2022-05-01 23:45:00.000 5 1
2 2022-05-02 18:07:00.000 66 0
2 2022-05-03 18:07:00.000 31 0

对自己的回答

FirstRes= VAR MYMIN =  CALCULATE(
MIN(Table[Date]),
FILTER ( Table, Table[IdRecord] = EARLIER(Table[IdRecord]))
)
RETURN   
IF(CALCULATE(
    MIN(MIN(Table[Date]),MYMIN),
    FILTER ( Table, Table[IdRecord] = EARLIER ( Table[IdRecord] ) )
) = Table[Date],1,0)