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
SofiaVaz
Helper I
Helper I

Voyage duration - DAX Expression

Hi all,

 

It's been a while since I've last use PB (and I was never an expert on this) so I need your help for what I think might be a simple measure.

 

Imagine a db with voy number, vessel name, VoyNav (voy no and vessel combined, witch is like an voyage ID) and ETA, ATA, ETD, ATD for each voyage, among other info.

 

If I want to know the duration of the voyage 75,  I have to do (ATA from voy 76) - (ATD from voy 75)

 

Can you help with na DAX expression to calculate that?

 

Thanks in advance.

1 ACCEPTED SOLUTION

@SofiaVaz 

Based on how I understood, I created the following sample data set to match your data and added a column to get the time
difference.

 

Fowmy_0-1595947013670.png

 

NAV Time = 
VAR NEXT_ATA = 
CALCULATE(
    MIN(VOYAGE[ATA]),
    ALLEXCEPT(VOYAGE,VOYAGE[VESSEL]),
    VOYAGE[ATA]>EARLIER(VOYAGE[ATA])
)

VAR CURRENT_ATD = 

[ATD]

RETURN
IF( 
    ISBLANK(NEXT_ATA), 
    BLANK(), 
    FORMAT(CURRENT_ATD - NEXT_ATA,"hh:mm:ss")
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@SofiaVaz voyageTime.PNG
Create a calculated column as above. 
You can also convert it into a measure.



Hope this helps.

Thanks

amitchandak
Super User
Super User

@SofiaVaz ,Can you share sample data and sample output in table format?

 

In this blog check -How can we get last non continuous day in a new calculated column?

a very similar approach would be needed

https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

Hi amitchandak 

I'm sorry I wasn't clear. Here's a sample. I'm trying to find and expression that will give the navigation time of a certain trip (knowing that each trip is time in port + time sailing)

 

Sample - PPB sailing time.png

Hi @SofiaVaz 

 

Below please find a calculated column that i think gets you what you are looking for.

It will get the duration for the vessel in the current row context based on the prior voyage number. you would have to update the formula to get the correct voyage number if they are not consecutive as your data suggests.

 

@SofiaVaz, found a bug and updated, sorry, got the fields and order backwards

 

 

 

Navigation Time = 
var vessel = 'Table'[Vessel]
var voyageNum = 'Table'[Voy #]
var startDate = CALCULATE(max('Table'[ATA]), filter(ALL('Table'), [Voy #] = voyageNum +1 && 'Table'[Vessel] = vessel))
return
DATEDIFF('Table'[ATD],startDate , MINUTE)

 

 

 

 

Hope this helps,

 

Richard



I hope this helps,
Richard

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

Proud to be a Super User!


Fowmy
Super User
Super User

@SofiaVaz 

Can you share some sample data and the expected result as data to have a clear understanding of your question?

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi Fowmy, 

 

I'm sorry I wasn't clear. Here's a sample. I'm trying to find and expression that will give the navigation time of a certain trip (knowing that each trip is time in port + time sailing)

 

Sample - PPB sailing time.png

 

@SofiaVaz 

Based on how I understood, I created the following sample data set to match your data and added a column to get the time
difference.

 

Fowmy_0-1595947013670.png

 

NAV Time = 
VAR NEXT_ATA = 
CALCULATE(
    MIN(VOYAGE[ATA]),
    ALLEXCEPT(VOYAGE,VOYAGE[VESSEL]),
    VOYAGE[ATA]>EARLIER(VOYAGE[ATA])
)

VAR CURRENT_ATD = 

[ATD]

RETURN
IF( 
    ISBLANK(NEXT_ATA), 
    BLANK(), 
    FORMAT(CURRENT_ATD - NEXT_ATA,"hh:mm:ss")
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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