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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
nerokasai
Frequent Visitor

Difference between 2 rows of a column (elapsed distance)

Hi all!

 

I would like to create either a column or measure which returns the difference of distance run on a recorded event date

Here's a sample source table:

Company NameEmployeeRecorded DateDifference (distance run on recorded date)Total distance run (km)
ABob2019-12-0122
ABob2019-12-0257
AJack2019-12-03310
BHannah2019-12-0244
BJohn2019-12-0537

 

Ideally, I would like to take data from the difference column to make a visual that represents the average distance ran on recorded date (average of the difference between two rows values) for each company or employee.

 

What would be the best way to approach this? Would I need Power Query for this?

 

Thank you!

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

OK, you can create the column you requested using EARLIER to filter ALL of your table and then using MAXX on that to grab the date (this gets you your previous row). Then you could use that date to filter out to the value for the last run. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395.... Let me know if you need further clarification but the technique is pretty much there. Although you might have an extra step to grab the previous run's distance.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Some like this as mentioned by @Greg_Deckler 

 difference of distance run on a recorded event date = 
 var _last = maxx(filter(table,table[Company Name]=earlier(table[Company Name]) && table[Recorded Date]<earlier(table[Recorded Date]) ),table[Total distance run (km)])
 return
 if(is(_last),table[Total distance run (km)], _last-table[Total distance run (km)])
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@nerokasai , There are couple of solutions provided. Hope something has worked out for you

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Works great! Thank you @Greg_Deckler  @amitchandak for your help!

Greg_Deckler
Community Champion
Community Champion

OK, you can create the column you requested using EARLIER to filter ALL of your table and then using MAXX on that to grab the date (this gets you your previous row). Then you could use that date to filter out to the value for the last run. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395.... Let me know if you need further clarification but the technique is pretty much there. Although you might have an extra step to grab the previous run's distance.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

I am not 100% following this. Does the data displayed represent sample source data? Or is it what you would like to achieve? If it is sample source data, what is your expected output?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler My apologies, I should have better clarified! 

 

The data shown displays the overall expected output I want to have.

 

To be more precise, I would like the column "Difference (distance run on recorded date") added to the sample source data, such that the overall data table would be like what I showed.

 

 

Some like this as mentioned by @Greg_Deckler 

 difference of distance run on a recorded event date = 
 var _last = maxx(filter(table,table[Company Name]=earlier(table[Company Name]) && table[Recorded Date]<earlier(table[Recorded Date]) ),table[Total distance run (km)])
 return
 if(is(_last),table[Total distance run (km)], _last-table[Total distance run (km)])
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors