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
databug
Frequent Visitor

Conditional column - rows condition for Time comparision

Hi team, I am a newbie and wants to compare  and match time for vehicle entry and exits to their latest ones to calculate the turn around time. Each vehicle has multiple entry and exit time stamp and I want to match the entry time with the earliest exit time and not the last exit time of that vehicle. Below is an example where the driver has two different entry time but with my current condition the first entry time matches with both greater than exit times. 

 

My "Validexit" column has the conditions if [Exit Date] > [Date] or ([Exit Date] = [Date] and [Exit Time] > [Time]) or [Exit Time] = null and [Driver] = [Exit Rec.Driver] or [Exit Time] = null then true else false

 

databug_0-1723128462550.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from Ashish_Mathur and Greg_Deckler  , please allow me to provide another insight: 
Hi  @databug ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Driver]=EARLIER('Table'[Driver])),[Time],,ASC)
Mod =
 MOD([Rank],2)
Group =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Driver]=EARLIER('Table'[Driver])&&'Table'[Rank]<=EARLIER('Table'[Rank])),[Mod])
Match =
var _match_entrytime=
MAXX(
    FILTER(ALL('Table'),  'Table'[Driver]=EARLIER('Table'[Driver])&&'Table'[Group]=EARLIER('Table'[Group])&&'Table'[Rank]=EARLIER('Table'[Rank])+1),[Time])
return
IF(
    _match_entrytime>=[Time] || _match_entrytime=BLANK(),TRUE(),FALSE())

2. Result:

vyangliumsft_0-1723168090340.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thanks for the reply from Ashish_Mathur and Greg_Deckler  , please allow me to provide another insight: 
Hi  @databug ,

 

Here are the steps you can follow:

1. Create calculated column.

Rank =
RANKX(
    FILTER(ALL('Table'),
    'Table'[Driver]=EARLIER('Table'[Driver])),[Time],,ASC)
Mod =
 MOD([Rank],2)
Group =
SUMX(
    FILTER(ALL('Table'),
    'Table'[Driver]=EARLIER('Table'[Driver])&&'Table'[Rank]<=EARLIER('Table'[Rank])),[Mod])
Match =
var _match_entrytime=
MAXX(
    FILTER(ALL('Table'),  'Table'[Driver]=EARLIER('Table'[Driver])&&'Table'[Group]=EARLIER('Table'[Group])&&'Table'[Rank]=EARLIER('Table'[Rank])+1),[Time])
return
IF(
    _match_entrytime>=[Time] || _match_entrytime=BLANK(),TRUE(),FALSE())

2. Result:

vyangliumsft_0-1723168090340.png

 

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

databug
Frequent Visitor

@Greg_Deckler Sorry for the confusion and not being clear. Below is my Sample text data.  I have entry and exit for each truck with the time stamp. I  want to match the first entry with the first exit and then subsequent entry and exit for each vehicle. The source file is getting updated with time stamps and some of the trucks don't have the exit time stamps till it data source gets updated.

TypeLocationTruckDriverTime
 ExitMoncton MOCKBS 1920-19  Gourav Singh8:24:30 AM
 EntryMoncton MOCKBS 1920-19  Gourav Singh9:34:17 AM
 ExitMoncton MOCKBS 1920-19  Gourav Singh10:42:56 AM
 EntryMoncton MOCKBS 1920-19  Gourav Singh11:56:50 AM
 ExitMoncton MOCKBS 1920-19  Gourav Singh12:14:55 PM
 ExitMoncton MOCKBS 2022-20  Renan Felippe7:17:14 AM
 ExitMoncton MOCKBS 2025-20  iurii savonik8:26:34 AM
 EntryMoncton MOCKBS 2025-20  iurii savonik9:55:28 AM
 ExitMoncton MOCKBS 2025-20  iurii savonik10:33:46 AM
 EntryMoncton MOCKBS 2025-20  iurii savonik11:42:20 AM
 ExitMoncton MOCKBS 2025-20  iurii savonik12:15:41 PM

 

Hi,

In another column, please show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@databug Not sure if a DAX solution is acceptable. Regardless, are these the results you are expecting? PBIX is attached below signature.

Valid Exit = 
    VAR __Type = [Type]
    VAR __Truck = [Truck]
    VAR __Location = [Location]
    VAR __Driver = [Driver]
    VAR __Time = [Time]
    VAR __Table = SELECTCOLUMNS( FILTER( 'Table', [Driver] = __Driver && [Location] = __Location && [Truck] = __Truck && [Type] = "Entry"  && [Time] < __Time ), "__Time", [Time] )
    VAR __PrevTime = MINX( __Table, [__Time] )
    VAR __Result = 
        SWITCH( TRUE(),
            __Type = "Entry", FALSE(),
            ISBLANK( __PrevTime ), FALSE(),
            TRUE()
        )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@databug Can you post your sample data as text? Also, I am not clear on your expected results.

 

Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors