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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Vrykolakas
Frequent Visitor

Please Help a newbie with this following simple calculation problem

I'm experimenting around, and I'm a little bit struggling with this one. Would really appreciate if anyone could enlighten me on how to solve the following :

My table is as shown :

2022-01-07_17h37_36.png

 

For each rented car, there's a Car-ID, reservation number ( that goes ASC ), and of course a start and end time.

What I'm trying to find here, is how long ( mins ) did the car stay still between each reservation.. 

My logic is as following, but I'm having difficulties writting it correctly. (so Please feel free to correct my mistakes, or open my mind to other ways) :
For each CarID, and for each Reservation, I need to calculate the periode between  End-Time of Resa1 and Start-Time of Resa2.
Now the only way I have to get the Resa2 for each Resa1, is maybe via Ranking ?
2022-01-07_17h22_20.png

I'm stuck with this since two days, and it's frustrating.
Thanks in advance for any help 🙂

2 ACCEPTED SOLUTIONS

Please try this measure expression. It calculates the overall time, the used time, and then subtracts them to get the idle time.

 

mahoneypat_0-1641819261121.png

 

Idle Time =
VAR totaltime =
    MAX ( Trip[End_time] ) - MIN ( Trip[Start_time] )
VAR usedtime =
    SUMX ( Trip, Trip[End_time] - Trip[Start_time] )
VAR result =
    FIXED ( usedtime3 )
RETURN
    result

 

Also, please check out this article. 

Calculate and Format Durations in DAX – Hoosier BI

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

v-stephen-msft
Community Support
Community Support

Hi @Vrykolakas ,

 

You want to calculate the difference between the end time of the previous row and the start time of the current row, right?

So using a rank column is a good idea! 

 

After rank column is created, create another column.

Period = var _end=CALCULATE(MAX('Trip'[End_time]),FILTER('Trip',[Rank]<EARLIER(Trip[Rank])))
return IF(ISBLANK(_end),BLANK(),FORMAT([Start_time]- _end,"HH:MM:SS") )

vstephenmsft_0-1641881916143.png

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @Vrykolakas ,

 

You want to calculate the difference between the end time of the previous row and the start time of the current row, right?

So using a rank column is a good idea! 

 

After rank column is created, create another column.

Period = var _end=CALCULATE(MAX('Trip'[End_time]),FILTER('Trip',[Rank]<EARLIER(Trip[Rank])))
return IF(ISBLANK(_end),BLANK(),FORMAT([Start_time]- _end,"HH:MM:SS") )

vstephenmsft_0-1641881916143.png

 

Best Regards,

Stephen Tao

 

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

smpa01
Super User
Super User

@Vrykolakas  can you please provide the sample data in a table format please? or upload the sample pbix in 1/g drive and share the link here?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hey @smpa01 
Thank you for getting back 🙂
I'm still stuck trying to solve this..

PBI file can be found HERE

I did create this report only for the question I asked here. The original pbix includes way more data... 

Please try this measure expression. It calculates the overall time, the used time, and then subtracts them to get the idle time.

 

mahoneypat_0-1641819261121.png

 

Idle Time =
VAR totaltime =
    MAX ( Trip[End_time] ) - MIN ( Trip[Start_time] )
VAR usedtime =
    SUMX ( Trip, Trip[End_time] - Trip[Start_time] )
VAR result =
    FIXED ( usedtime3 )
RETURN
    result

 

Also, please check out this article. 

Calculate and Format Durations in DAX – Hoosier BI

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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