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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Query to return difference between two date/time in same column

I am trying to create a new column that will give the time difference between sequental rows. For example the new column would give the difference of 0 seconds between the first two rows. I tried using DAX to create this but kept getting the error of not having enough memory. Im hoping I can do this in the query editor.

power bi image.PNG

5 REPLIES 5
v-easonf-msft
Community Support
Community Support

Hi @Anonymous 

Could you please tell me whether your problem has been solved?

If it is,  please mark the helpful replies or your reply as Answered to close this thread?

 

Best Regards,
Community Support Team _ Eason

AiolosZhao
Memorable Member
Memorable Member

Hi @Anonymous ,

 

I'm not very familiar with the M query, so I didn't find a table function to solve that.

 

But I have an idea to make this, I think it will work, and if anyone can do it in M query I will be glad to see that.

 

Steps:

1. Copy your table, we call it B table(original one is A table).

2. Add index(from 1) in A table and also add index(from 0) in B table

3. Merge A and B using index, then you will get the next line value.

4. then you can calculate the difference.

 

Hope I have clarified the method.

Aiolos Zhao





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

Proud to be a Super User!




Anonymous
Not applicable

Still getting the error of not enough memory

Not sure applicable for your case.

 

I created 150K rows of dates. Taken to Power BI in unsorted order. In edit query/ transform data. I sorted and created an index column. As in my case, I wanted dates to be in sorted order of time; to take diff. No other Primary key option. Now in your case you need to find one. In case you have created date/Updated date, from DB. Basically line number.  You can sort on those

Then I created this column

Previous Row Date = MINX(filter(Sheet1,Sheet1[Index]=(EARLIER(Sheet1[Index])-1)),Sheet1[Date])

 

This gave the answer quickly.

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.