cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Return Previous Row's Data, Direct Query SQL

Hi All,

 

I am trying to show the time difference between 'Time Created' by Employee. I have found solutions that use a calculated column, but I am using a direct query to a SQL server and this seems to prevent me from being able to use calculated columns.

 

The new column will show 7 min, 5 min, 5 min, etc.

thomas_p_1-1597759100955.png

 

Any help would be appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

@thomas_p , You will not be able to create a column as earlier is not supported.

Try a measure like this

diff =
maxx(summarize(Table, Table[Employee], Table[time created],"_1",
max(Table[time created]) -maxx(filter(allselected(Table), Table[employee] =max(Table[employee]) && Table[time created] <max(Table[time created])),Table[time created])
),[_1])

 

This should work with the employee and time created. See if this can work for you

Few supported column I covered in playlist - https://www.youtube.com/watch?v=My0bLn9voo4&list=PLPaNVDMhUXGbKatyDdOhGbTL3xW2Xy6pA

 

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

3 REPLIES 3
Highlighted
Super User IV
Super User IV

@thomas_p , You will not be able to create a column as earlier is not supported.

Try a measure like this

diff =
maxx(summarize(Table, Table[Employee], Table[time created],"_1",
max(Table[time created]) -maxx(filter(allselected(Table), Table[employee] =max(Table[employee]) && Table[time created] <max(Table[time created])),Table[time created])
),[_1])

 

This should work with the employee and time created. See if this can work for you

Few supported column I covered in playlist - https://www.youtube.com/watch?v=My0bLn9voo4&list=PLPaNVDMhUXGbKatyDdOhGbTL3xW2Xy6pA

 

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

View solution in original post

Highlighted

@amitchandak thank you, this works exactly how I need it to!

Highlighted
Resolver I
Resolver I

@thomas_p 

Alternate Solution in SQL using the Lead function and later Date Difference as follows

1. LEAD([Time Created],1) OVER (PARTITION BY Employee ORDER BY [Time Created]) AS Lead
2. DATEDIFF(MINUTE,[Time Created],LEAD([Time Created],1) OVER (PARTITION BY Employee ORDER BY [Time Created])) AS [Difference]

 

lead.PNG

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors