Forum Discussion
GOT2021
1 year agoFrequent Visitor
Calculate DateTime Diff In Group BY with DAX
Hi, my problem was this : Date Id User Job 10/01/2024 15:01:24 001 Adam Nurse 10/01/2024 15:11:24 001 Max Nurse 10/01/2024 16:01:24 001 George Doctor 15/01/2024 08:00:0...
- Anonymous1 year ago
Hi GOT2021 ,
Based on your description, you can try the following code to see if it's what you're expectingFilter measure = VAR curId = SELECTEDVALUE('Nurse table'[Id]) VAR curJob = SELECTEDVALUE('Nurse table'[Job]) VAR curTime = SELECTEDVALUE('Nurse table'[Date]) VAR People = CALCULATETABLE('Nurse table', ALLSELECTED('Nurse table'), 'Nurse table'[Id] = curId) VAR maxDate = MAXX(People, [Date]) VAR minDate = MINX(People, [Date]) VAR diffTime = DATEDIFF(minDate, maxDate, MINUTE) RETURN SWITCH( TRUE(), COUNTROWS(People) = 1, "Y", MAXX(FILTER(People, 'Nurse table'[Job] <> "Doctor"), [Date]) = curTime && curJob <> "Doctor", "Y", MAXX(FILTER(People, 'Nurse table'[Job] = "Doctor"), [Date]) = curTime && curJob = "Doctor", "Y", diffTime > 60 && MINX(FILTER(People, 'Nurse table'[Job] <> "Doctor"), [Date]) = curTime && curJob <> "Doctor", "Y", diffTime > 60 && MINX(FILTER(People, 'Nurse table'[Job] = "Doctor"), [Date]) = curTime && curJob = "Doctor", "Y", "N" )Best regards,
Albert HeIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Anonymous
1 year agoNot applicable
Hi GOT2021 ,
Based on your description, you can try the following code to see if it's what you're expecting
Filter measure =
VAR curId = SELECTEDVALUE('Nurse table'[Id])
VAR curJob = SELECTEDVALUE('Nurse table'[Job])
VAR curTime = SELECTEDVALUE('Nurse table'[Date])
VAR People = CALCULATETABLE('Nurse table', ALLSELECTED('Nurse table'), 'Nurse table'[Id] = curId)
VAR maxDate = MAXX(People, [Date])
VAR minDate = MINX(People, [Date])
VAR diffTime = DATEDIFF(minDate, maxDate, MINUTE)
RETURN
SWITCH(
TRUE(),
COUNTROWS(People) = 1, "Y",
MAXX(FILTER(People, 'Nurse table'[Job] <> "Doctor"), [Date]) = curTime && curJob <> "Doctor", "Y",
MAXX(FILTER(People, 'Nurse table'[Job] = "Doctor"), [Date]) = curTime && curJob = "Doctor", "Y",
diffTime > 60 && MINX(FILTER(People, 'Nurse table'[Job] <> "Doctor"), [Date]) = curTime && curJob <> "Doctor", "Y",
diffTime > 60 && MINX(FILTER(People, 'Nurse table'[Job] = "Doctor"), [Date]) = curTime && curJob = "Doctor", "Y",
"N"
)
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- GOT20211 year agoFrequent Visitor
Hi Anonymous, Indeed, that's what I was expecting. Thank you so much 🙂