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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Pandadev
Post Prodigy
Post Prodigy

Get arrival time from previous row add 5 minutes and add to next row depart time

Hi I have a table of data with blanks that need to be filled in from the previous row

The original table looks like this

Origin                 Destination           Depart        Arrival             Code 
Kodiak                Kitoi Bay               11:00AM     11:25AM         501 
                           Seal Bay                                   11:45AM         511
                           Port William                             12:25PM         521

 

I need to fill in the blanks Origin by adding the previous destination and then I need to fill in the blank depart by previous arrival + 5 mins

This is how the output should look

 

Origin                 Destination           Depart        Arrival             Code 
Kodiak                Kitoi Bay               11:00AM     11:25AM         501 
Kitoi Bay             Seal Bay                11:30AM     11:45AM         511
Seal Bay             Port William          11:50AM     12:25PM         521

1 ACCEPTED SOLUTION
AlexanderPrime
Solution Supplier
Solution Supplier

Assuming your table is called Table1 (Replace Table1 with your table name in all the code below)

IN POWER QUERY (Transform Data)


First you'll need to make an index column within PowerQuery/Transform Data so DAX will know how to declare an order.

Then add a custom column, call it NextDepart and add the following code

[Arrival] + #duration(0,0,5,0)

Then set this new column to be in the "TIME" data format.

 

Exit out of Power Query, (close and apply)
IN DAX

Make 2 columns to replace Origin and Depart with the following DAX code:

 

Origin2 =
VAR PreviousDestination = CALCULATE(MAX(Table1[Destination]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))
RETURN
IF((Table1[Origin]=""),PreviousDestination,Table1[Origin])
 
Depart2 = VAR PreviousArrival = CALCULATE(MAX(Table1[NextDepart]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))
RETURN
IF(ISBLANK(Table1[Depart]),(PreviousArrival),Table1[Depart])
 
AlexanderPrime_0-1650618972645.png

 

 

Note: For Origin2. If it's not populating correctly. replace IF((Table1[Origin]="") in the code with (ISBLANK(Table1[Origin])

 

 

 


Please note - I am not affiliated with Microsoft, I'm just an end user like yourself.
Just a regular guy doin' Data Science.

If my post has helped you, please don't forget to thumbs up or click "Accept as solution" if it solved your problem!

View solution in original post

2 REPLIES 2
AlexanderPrime
Solution Supplier
Solution Supplier

Assuming your table is called Table1 (Replace Table1 with your table name in all the code below)

IN POWER QUERY (Transform Data)


First you'll need to make an index column within PowerQuery/Transform Data so DAX will know how to declare an order.

Then add a custom column, call it NextDepart and add the following code

[Arrival] + #duration(0,0,5,0)

Then set this new column to be in the "TIME" data format.

 

Exit out of Power Query, (close and apply)
IN DAX

Make 2 columns to replace Origin and Depart with the following DAX code:

 

Origin2 =
VAR PreviousDestination = CALCULATE(MAX(Table1[Destination]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))
RETURN
IF((Table1[Origin]=""),PreviousDestination,Table1[Origin])
 
Depart2 = VAR PreviousArrival = CALCULATE(MAX(Table1[NextDepart]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))
RETURN
IF(ISBLANK(Table1[Depart]),(PreviousArrival),Table1[Depart])
 
AlexanderPrime_0-1650618972645.png

 

 

Note: For Origin2. If it's not populating correctly. replace IF((Table1[Origin]="") in the code with (ISBLANK(Table1[Origin])

 

 

 


Please note - I am not affiliated with Microsoft, I'm just an end user like yourself.
Just a regular guy doin' Data Science.

If my post has helped you, please don't forget to thumbs up or click "Accept as solution" if it solved your problem!

Thankyou , the code worked perfectly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.