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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BrandonL
Employee
Employee

Calculating Duration from 2 tables

I have 2 tables:

  • First contains Start Time
  • Second Contains End Time

How do i calculate the duration between these times using 2 unique id pivots: Session_ID & Player_ID as each "session" will have multiple player entries and each table will have multiple sessions. Also each player can participate in multiple sessions just not simultaneously. 

Event_IDPlayer_IDSession_IDTimeStampEvent
161NGL_I6XtO3/20/2020 6:37:36 AMPlayer_session_Start
32162COOZB3/20/2020 9:54:30 AMPlayer_session_Start
110083NUDGX3/20/2020 10:04:06 AMPlayer_session_Start

 

Event_IDPlayer_IDSession_IDTimeStampEvent
5001NGL_I6XtO3/20/2020 8:31:55 AMPlayer_session_End
220052COOZB3/20/2020 11:23:15 AMPlayer_session_End
194563NUDGX3/20/2020 12:45:32 PMPlayer_session_End
1 ACCEPTED SOLUTION
ibarrau
Super User
Super User

Hi. How is the relationship between the tables?

If you have a 1-1 then you have no problem you can do two things, merge them together or create a column in table 1 like:

DATEDIFF ( Table1[StartDate]; RELATED(Table2[EndDate]); HOUR )

You can use datediff to get any interval of time you want.

 

If you have 1-* we should talk again, let us know the relationship.

Regards, 


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

Happy to help!

LaDataWeb Blog

View solution in original post

3 REPLIES 3
ibarrau
Super User
Super User

Hi. How is the relationship between the tables?

If you have a 1-1 then you have no problem you can do two things, merge them together or create a column in table 1 like:

DATEDIFF ( Table1[StartDate]; RELATED(Table2[EndDate]); HOUR )

You can use datediff to get any interval of time you want.

 

If you have 1-* we should talk again, let us know the relationship.

Regards, 


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

Happy to help!

LaDataWeb Blog

All of the tables in this dashboard are linked as *-* unfortunately as each table can contain multiple rows with the same player_id or session_id. However there is only one row each table with the unique combination of a single player_id AND session_id together if that makes sesnse. 

 

When working in the hierarchy it doesnt allow me to select any other type of relationships. Says its invalid.

Did you try creating a new column with the combine values of player_id and session_id on each table and then relate them? That way you might get a result of 1-* or 1-1. If you have this you will be able to create the measure I have just suggested.

 

Be careful with the new column cases, be sure to have all trim and lower or upper case if they contain chars.

 

Regards,


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

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors