degrees-of-freedom
degrees-of-freedom

Reputation: 873

Measure max datetime per Id in Dax

Suppose that you have a table with two columns ("ID","DATETIME"). For each "ID" there are multiple rows with different datetimes. I want to create a third column named "IS_LAST" which has a Boolean data type. For each row I want to filter the table with the "ID" present in the row and want to check if the "DATETIME" in row is the latest. If yes, "IS_LAST" goes to TRUE else FALSE.

My tentative is: IF(COUNTROWS(FILTER(TABLE, TABLE[ID] = [ID] && TABLE[DATETIME] > [DATETIME]) = 0)), TRUE, FALSE). But this gives TRUE for all rows.

Upvotes: 0

Views: 1197

Answers (1)

davidebacci
davidebacci

Reputation: 30264

enter image description here

Is Last = 
 
VAR latest =  CALCULATE(MAX('Table'[time]), ALLEXCEPT('Table','Table'[id]))
RETURN
IF(SELECTEDVALUE('Table'[time]) = latest, TRUE())

Upvotes: 1

Related Questions