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
Tapemeasure
Regular Visitor

Date Difference between Rows in a Measure

Hi,

 

I'm trying to work out how to use a measure to caclualte the datedifference between rows

 

I've got an dataset that looks like (Date formatting is DD/MM/YYYY)

 

IDStartDate
113/08/2017
213/08/2017
312/08/2017
424/08/2017

 

So far, I've added the following Measure using RANKX 

 

RankMeasure = RANKX(
ALLSELECTED(TABLE),
CALCULATE(
FIRSTDATE(TABLE[StartDate])),,ASC,Dense)

 

When i add this to a table visualisation i get the follow

 

IDStartDateRankMeasure
113/08/2017     2
213/08/2017     2
312/08/2017     1
424/08/2017     3

 

So far so good, Now i'm trying to calculate the DateDifference (in days) between the rows so the result should look like

 

IDStartDateRankMeasureDateDifference (days)
113/08/2017     21
213/08/2017     21
312/08/2017     10
424/08/2017     311

 

Any help would be great.

 

Thanks

1 ACCEPTED SOLUTION
Tapemeasure
Regular Visitor

Hey everyone, thanks for your help, 

 

I managed to do it using the following measure (turns out, I don't need the rank column)

 

DaysBetweenFaults = 

var currentDate = SELECTEDVALUE(Table[StartDate])

var previousDate = CALCULATE(

Max(Table[StartDate]),

ALLSELECTED(Table),

Table[StartDate] < currentDate)

return

if(not ISBLANK(DATEDIFF(previousDate,currentDate,DAY)),DATEDIFF(previousDate,currentDate,DAY),0)

View solution in original post

3 REPLIES 3
Tapemeasure
Regular Visitor

Hey everyone, thanks for your help, 

 

I managed to do it using the following measure (turns out, I don't need the rank column)

 

DaysBetweenFaults = 

var currentDate = SELECTEDVALUE(Table[StartDate])

var previousDate = CALCULATE(

Max(Table[StartDate]),

ALLSELECTED(Table),

Table[StartDate] < currentDate)

return

if(not ISBLANK(DATEDIFF(previousDate,currentDate,DAY)),DATEDIFF(previousDate,currentDate,DAY),0)
Anonymous
Not applicable

Hi @Tapemeasure 

I create a Calculated Column to rank StartDate:

Rank = RANKX('Table','Table'[StartDate],,ASC,Dense)

And I build a Day column:

Day = DAY('Table'[StartDate])

Then I use a measure to achieve your goal:

DateDifference (days) =

IF(MAX('Table'[Rank])=1,

0,

MAX('Table'[Day])-CALCULATE(VALUES('Table'[Day]),FILTER(ALL('Table'),'Table'[Rank]=MAX('Table'[Rank])-1)))

Result:

1.png

You can download the pbix file form this link:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/tongzhou_qiuyunus_onmicrosoft_com/EbLGEcfcu9tEsC0r...

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

amitchandak
Super User
Super User

@Tapemeasure , If IS/Rank are continous

new column = datediff(Table[Date], maxx(filter(Table,Table[ID] =earlier(Table[ID])-1) ,Table[Date]),day)

// non-continous 
new column 2 =
var _ min = maxx(filter(Table,Table[ID] < earlier(Table[ID])-1) ,Table[ID])
return
datediff(Table[Date], minx(filter(Table,Table[ID] =_min) ,Table[Date]),day)

 

Both Measure and column methods is disuccsed here too

https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

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