Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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)
| ID | StartDate |
| 1 | 13/08/2017 |
| 2 | 13/08/2017 |
| 3 | 12/08/2017 |
| 4 | 24/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
| ID | StartDate | RankMeasure |
| 1 | 13/08/2017 | 2 |
| 2 | 13/08/2017 | 2 |
| 3 | 12/08/2017 | 1 |
| 4 | 24/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
| ID | StartDate | RankMeasure | DateDifference (days) |
| 1 | 13/08/2017 | 2 | 1 |
| 2 | 13/08/2017 | 2 | 1 |
| 3 | 12/08/2017 | 1 | 0 |
| 4 | 24/08/2017 | 3 | 11 |
Any help would be great.
Thanks
Solved! Go to Solution.
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)
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)
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:
You can download the pbix file form this link:
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.
@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
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 104 | |
| 82 | |
| 72 | |
| 46 | |
| 35 |