cancel
Showing results for
Did you mean:
Highlighted
Regular Visitor

## DATEDIFF between Rows

Hello,

I have a question about how to calculate datediff between rows. I have dataset like below:

 Trackingtocken createdon 1 01.08.2018 08:00 1 01.08.2018 08:01 1 01.08.2018 08:12 1 01.08.2018 08:14 1 01.08.2018 08:15 1 01.08.2018 10:31

What I need is a calculated column where datediff (MIN or HOUR) between each row is calculated (from the very beginning).

Something like the outcome below (based on my example):

 Datediff 011121....

Regards

Magomed.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team

## Re: DATEDIFF between Rows

HI, @Magomed

After my test, you could do these follow my steps as below:

Step1:

`group rank = RANKX(FILTER(Table1,Table1[Trackingtocken]=EARLIER(Table1[Trackingtocken])),Table1[createdon],,ASC)`

Step2:

Use EARLIER Function add a datediff column

`Datediff = DATEDIFF(CALCULATE(MAX(Table1[createdon]),FILTER(Table1,Table1[Trackingtocken]=EARLIER(Table1[Trackingtocken])&&Table1[group rank]=EARLIER(Table1[group rank])-1)),Table1[createdon],MINUTE)`

Result:

here is pbix, please try it.

https://www.dropbox.com/s/0v0qnnue9j1hvyx/DATEDIFF%20between%20Rows.pbix?dl=0

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Super User

## Re: DATEDIFF between Rows

See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...

### I have book! Learn Power BI from Packt

Proud to be a Datanaut!

Community Support Team

## Re: DATEDIFF between Rows

HI, @Magomed

After my test, you could do these follow my steps as below:

Step1:

`group rank = RANKX(FILTER(Table1,Table1[Trackingtocken]=EARLIER(Table1[Trackingtocken])),Table1[createdon],,ASC)`

Step2:

Use EARLIER Function add a datediff column

`Datediff = DATEDIFF(CALCULATE(MAX(Table1[createdon]),FILTER(Table1,Table1[Trackingtocken]=EARLIER(Table1[Trackingtocken])&&Table1[group rank]=EARLIER(Table1[group rank])-1)),Table1[createdon],MINUTE)`

Result:

here is pbix, please try it.

https://www.dropbox.com/s/0v0qnnue9j1hvyx/DATEDIFF%20between%20Rows.pbix?dl=0

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Regular Visitor

## Re: DATEDIFF between Rows

Hi Greg,

Thanks a lot! I will test your approach.

Regards

Magomed.

Regular Visitor

## Re: DATEDIFF between Rows

Hi Lin,

Thank you very much, it worked for me :).

Regards

Magomed.

Announcements

#### New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

#### Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (3,394)