Forum Discussion
Filtering Dates
To achieve this in DAX (Data Analysis Expressions), you can create a calculated column that flags the rows where LogInDate and LogOutDate occur on the same day and then identify the closest LogOutDate that occurs on the same day or after the LogInDate. Below is the DAX code to implement this logic:
PairFlag =
VAR CurrentUserId = 'YourTable'[User Id]
VAR CurrentLogInDate = 'YourTable'[LogInDate]
VAR SameDayLogOut =
FILTER(
'YourTable',
'YourTable'[User Id] = CurrentUserId &&
'YourTable'[LogOutDate] >= CurrentLogInDate &&
DATEDIFF('YourTable'[LogInDate], CurrentLogInDate, DAY) = 0
)
VAR ClosestLogOutDate =
MINX(
FILTER(
SameDayLogOut,
'YourTable'[LogOutDate] >= CurrentLogInDate
),
'YourTable'[LogOutDate]
)
RETURN
IF(
'YourTable'[LogOutDate] = ClosestLogOutDate,
"x",
BLANK()
)
Replace 'YourTable' with the actual name of your table in your Power BI model. This DAX code creates a calculated column called PairFlag which checks for each row if there exists a LogOutDate on the same day as the LogInDate, and then finds the closest LogOutDate on the same day or after the LogInDate. If the LogOutDate is the closest one, it flags it with "x", otherwise, it remains blank.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.