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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
areias_br
Frequent Visitor

Personalized Collum based on the next row value

Hi,


I have a table with the following colluns:

 

Date | Hour | OperationCode | ID

 

Whenever I have a change in a operation, a new line is created with the record of the hour that operation started. 

I need to create a new collum with the "Operation Duration". Being so, it will always be the Hour of the next line - the Hour of current line. 

 

Any idea on how can i do it in Power Query? 

1 ACCEPTED SOLUTION

you can try this

 

datehour = 'Table'[Date]+'Table'[Hour]

 

Column =
VAR _next=MINX(FILTER('Table','Table'[datehour]>EARLIER('Table'[datehour])),'Table'[datehour])
var _hour=maxx(FILTER('Table','Table'[datehour]=_next),'Table'[Hour])
return if (ISBLANK(_hour),blank(), if ('Table'[Hour]>_hour, DATEDIFF((date(2020,1,1)+'Table'[Hour]),(date(2020,1,2)+_hour),MINUTE),DATEDIFF((date(2020,1,1)+'Table'[Hour]),(date(2020,1,1)+_hour),MINUTE)))
 
 
11.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Sure!

02/08/2024 | 13:50 | Navigation | 1
02/08/2024 | 23:30 | Mooring | 2
03/09/2024 | 01:00 |  Moored | 3

I expect to get the personalized collum as the following

02/08/2024 | 13:50 | Navigation | 1 | 580 minutes
02/08/2024 | 23:30 | Mooring | 2 | 90 minutes
03/09/2024 | 01:00 |  Moored | 3 | ...

how you get 580 mins and 90 mins?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




02/08/2024 | 13:50 | Navigation | 1 | 580 minutes (23:30 - 13:50 = 09:40 => 09*60 + 40)
02/08/2024 | 23:30 | Mooring | 2 | 15 minutes (23:45 - 23:30 = 15)
02/08/2024 | 23:45 |  Moored | 3 | ...

I've changed the last value because it gets a little bit more complicated when day changes.

you can try this

 

datehour = 'Table'[Date]+'Table'[Hour]

 

Column =
VAR _next=MINX(FILTER('Table','Table'[datehour]>EARLIER('Table'[datehour])),'Table'[datehour])
var _hour=maxx(FILTER('Table','Table'[datehour]=_next),'Table'[Hour])
return if (ISBLANK(_hour),blank(), if ('Table'[Hour]>_hour, DATEDIFF((date(2020,1,1)+'Table'[Hour]),(date(2020,1,2)+_hour),MINUTE),DATEDIFF((date(2020,1,1)+'Table'[Hour]),(date(2020,1,1)+_hour),MINUTE)))
 
 
11.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.