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! Request now

Reply
JKoivu
Helper I
Helper I

Calculate min/max days between events

I have a table with repair data for vehicles. I need to calculate what was the smallest and largest timeframe (in days) between them. Let's say I have a date slicer on my report, and after selecting dates I have the following raw data:

 

JKoivu_0-1601991787366.png

 

I would then like to show a Power BI table that looks something like this:

JKoivu_1-1601992196118.png

 

Based on the data, min date diff would be 11 days and max date diff would be 42 days.

 

So the question is, what is the best way of doing this? My first instinct was to create a measure with EARLIER thrown in, but I don't really understand how EARLIER works so couldn't figure out how to do it. The other option that I thought of was to create a new calculated column with the difference to previous repair, something like this:

JKoivu_2-1601992553587.png

This way I could just create simple measures like: Min date diff = MIN(Repairs[Days from previous]). Problem is that I don't really know how to write such column efficiently without slowing the data refresh, and I would really prefer using a measure anyways if that's possible.

 

1 ACCEPTED SOLUTION

@JKoivu , diff from previous date 

As column  

From previous repair =
datediff (MaxX(filter(Table,[Vehicle_id] =earlier([Vehicle_id]) && [Date] <earlier([Date])),[Date]), [Date], day)

As measure 

From previous repair measure =
datediff (MaxX(filter(allselcted(Table),[Vehicle_id] =max([Vehicle_id]) && [Date] <max([Date])),[Date]), [Date], day)

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

3 REPLIES 3
amitchandak
Super User
Super User

@JKoivu , You can get measures like this

 


Measure 1 =
datediff(max([Date]), calculate(max([Date]), allexcept(Table,[Vehicle_id])), day)


Measure 2 =
datediff( calculate(min([Date]), allexcept(Table,[Vehicle_id])),max([Date]), day)

 

or you can get columns

 

Column 1 =
datediff(([Date]), calculate(max([Date]), filter(Table,[Vehicle_id] =earlier([Vehicle_id]))), day)


Column 2 =
datediff( calculate(min([Date]), filter(Table,[Vehicle_id] =earlier([Vehicle_id]))),([Date]), day)

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

@amitchandak , thanks for you reply! I tried these with the following results: Measure 1 (which I figured is the max diff?) returns 0, and the measure 2 returns 346, so these don't work like I imagined.

 

This is the result for the columns:

JKoivu_0-1601995851471.png

The Column 1 is pretty close to what I need, which is cool! But it seems to calculate datediff from the latest, is it possible to have it subtract the value from previous row?

@JKoivu , diff from previous date 

As column  

From previous repair =
datediff (MaxX(filter(Table,[Vehicle_id] =earlier([Vehicle_id]) && [Date] <earlier([Date])),[Date]), [Date], day)

As measure 

From previous repair measure =
datediff (MaxX(filter(allselcted(Table),[Vehicle_id] =max([Vehicle_id]) && [Date] <max([Date])),[Date]), [Date], day)

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors