Forum Discussion
DAX
Hi, I am truly sorry if this question has been asked before but I can't seem to find the answer in the internet.
I have a table in a direct query mode that is populated everytime someone send a request :
From the Event Date column, I want to create a calculated column or measure that compute the duration between current date and previous entry date like this :
| Vessel ID | Event Date | Duration |
| 9679751 | 7/2/2021 | 0 |
| 9679751 | 19/2/2021 | 12 |
| 9679751 | 25/2/2021 | 6 |
| 9316268 | 12/2/2021 | 0 |
| 9316268 | 20/2/2021 | 8 |
| 9704544 | 15/2/2021 | 0 |
This is what I have right now:
Duration =
VAR CurrentDate = ONOFF[EventDate]
VAR PreviousDate =
CALCULATE (
MAX ( ONOFF[EventDate]),
FILTER (ALLSELECTED(ONOFF),
ONOFF[VesselId] = ONOFF[VesselId] & ONOFF[EventDate] < CurrentDate
)
)
RETURN
CurrentDate - PreviousDate
Can anyone help me?
1 Reply
- amitchandak
Super User
Anonymous , Try a new measure like
Duration =
datediff( max(Table[Event Date]), calculate(max(Table[Event Date]), filter(allselected(Table), Table[Vessel ID] = max(Table[Vessel ID]) && Table[Event Date] < max(Table[Event Date]))), day)or
Duration =
sumx(ADDCOLUMNS(summarize(Table,Table[Vessel ID],[Event Date]), "_1" datediff( max(Table[Event Date]), calculate(max(Table[Event Date]), filter(allselected(Table), Table[Vessel ID] = max(Table[Vessel ID]) && Table[Event Date] < max(Table[Event Date]))), day)),[_1])