Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
Solved! Go to Solution.
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:
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
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:
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
@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.
Type | Location | Truck | Driver | Time |
Exit | Moncton MOC | KBS 1920-19 | Gourav Singh | 8:24:30 AM |
Entry | Moncton MOC | KBS 1920-19 | Gourav Singh | 9:34:17 AM |
Exit | Moncton MOC | KBS 1920-19 | Gourav Singh | 10:42:56 AM |
Entry | Moncton MOC | KBS 1920-19 | Gourav Singh | 11:56:50 AM |
Exit | Moncton MOC | KBS 1920-19 | Gourav Singh | 12:14:55 PM |
Exit | Moncton MOC | KBS 2022-20 | Renan Felippe | 7:17:14 AM |
Exit | Moncton MOC | KBS 2025-20 | iurii savonik | 8:26:34 AM |
Entry | Moncton MOC | KBS 2025-20 | iurii savonik | 9:55:28 AM |
Exit | Moncton MOC | KBS 2025-20 | iurii savonik | 10:33:46 AM |
Entry | Moncton MOC | KBS 2025-20 | iurii savonik | 11:42:20 AM |
Exit | Moncton MOC | KBS 2025-20 | iurii savonik | 12:15:41 PM |
Hi,
In another column, please show the expected result.
@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
@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.
User | Count |
---|---|
73 | |
73 | |
39 | |
25 | |
23 |
User | Count |
---|---|
96 | |
93 | |
51 | |
43 | |
42 |