Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Barry_Sophus
Frequent Visitor

Filtering Dates

For each User ID,  I need to identify the rows where LogInDates occurs on the same day. After that I need to identify the closest LogOutDates that occurs on the same day or after. There can be only two dates in a pair but there can be multiple pairs for each UserId. The LogOutDate and is not dependant on the LoginDate. How do I do this in Dax?

 

User IdLogInDateLogOutDateExpected
A12/29/20131/1/2014 
A12/30/20141/1/2015x
A12/29/20141/1/2015 
A12/30/20141/1/2016x
B1/30/20152/1/2015x
B1/30/20152/1/2015x
B1/30/20154/1/2015 
B1/30/20153/1/2015 
C4/26/20165/1/2016 
C5/27/20166/1/2016x
C5/27/20166/1/2016x
C5/28/20166/2/2016 
C5/29/20166/3/2016 

 

3 REPLIES 3
Barry_Sophus
Frequent Visitor

My appologies. I don't think what I explained was clear. What I am wanting is For each User ID, I want to determine if the LogoutDate is on/after the current row. If it is then flag those two rows then go to the next unflagged row and perform the same analysis.

ThxAlot
Super User
Super User

Simple enough

ThxAlot_0-1706945695845.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



123abc
Community Champion
Community Champion

 

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.

 

 

 

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.