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
Anonymous
Not applicable

Calculate difference between latest shift date/time and previous shift date/time - direct query data

I am using direct query to bring in time and attendance data into my data model.  Import would be impractical due to the size of the dataset. 

 

I need to be able to compare shifts worked for each employee with previous shift worked, and calculate the time difference between the starting time of the 2 shifts. 

 

Is this even possible using direct query, with the limitations on using calculated columns etc?

 

Jules_Brinkley_0-1664790832543.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous ,

No you can not have a calculated column for that, You have to create a measure

 

Measure =

var _max = maxx(filter(allselected(Table), Table[Employee] = max(Table[Employee]) && Table[Pay Start] < max(Table[Pay Start])) , Table[Pay Start])
return
datediff(_max, max(Table[Pay Start]), day)


If needed use one more measure

sumx(Summarize( Table, Table[Employee],Table[Pay Start]), [Measure])

 

use averageX if needed

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you so much this is perfect

amitchandak
Super User
Super User

@Anonymous ,

No you can not have a calculated column for that, You have to create a measure

 

Measure =

var _max = maxx(filter(allselected(Table), Table[Employee] = max(Table[Employee]) && Table[Pay Start] < max(Table[Pay Start])) , Table[Pay Start])
return
datediff(_max, max(Table[Pay Start]), day)


If needed use one more measure

sumx(Summarize( Table, Table[Employee],Table[Pay Start]), [Measure])

 

use averageX if needed

 

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