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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
GJUDGE
Helper II
Helper II

Help with DateDiff

Probably a straightforward one for most, but how to do I write a measure to caluclate the movement in days of each construction project from one month to the next? So for example, the movement in construction date for project A would show 30 days?

 

It would be easier for me to have separate measures for changes in construction start date and commissioning date. 

 

Also is there any way to make this dynamic by referring to the max reporting period and one less than this as opposed to using Sept-21 and Aug-21 in the measure?

 

Thanks,

 

ProjectOutputConstruction Start DateCommissioning DateReporting Period
A5001/01/202301/06/2023Aug-21
B2501/04/202307/04/2023Aug-21
C5001/05/202301/07/2023Aug-21
A5001/02/202301/06/2023Sep-21
B2501/04/202307/04/2023Sep-21
C5001/05/202301/06/2023Sep-21

 

 

10 REPLIES 10
Anonymous
Not applicable

Hi @GJUDGE ,

 

 the COD date hasn't changed in the most recent two months

The latest date is 2025-Feb, so if there do not exist COD= 2025-Jan and 2024-Dec, then datediff should be 0 ?

 

Measure 2 = 
var _last=CALCULATE(MAX('Table'[Construction Start Date]),ALLEXCEPT('Table','Table'[Project]))
var _pre= MAXX(FILTER(ALL('Table'),'Table'[Project]=MAX('Table'[Project]) && [Construction Start Date]<_last),[Construction Start Date])
return IF(DATEDIFF(_pre,_last,MONTH)<=2,DATEDIFF( _pre,_last,DAY),0)

Eyelyn9_0-1635497772412.png

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

@Anonymous Yes, the COD date hasn't changed, but even if this is the case I need the measure to only compare the COD dates of the last two months. Even is this is zero. For example, in project B in the test data I provided, I should still see a return of zero. Basically what I want to do is COD Date (Filltered reporting period for the latest month) minus COD Date (filtered for reporting period last month minus 1 month).

Anonymous
Not applicable

Hi @GJUDGE ,

 

I have added a row to simply reproduce data as you said your actual data contains many months data.

My first measure returns the date diff for each changed .

Eyelyn9_0-1635494252220.png

Below will return the diff between the latest two date:

 

Measure 2 = 
var _last=CALCULATE(MAX('Table'[Construction Start Date]),ALLEXCEPT('Table','Table'[Project]))
var _pre= MAXX(FILTER(ALL('Table'),'Table'[Project]=MAX('Table'[Project]) && [Construction Start Date]<_last),[Construction Start Date])
return DATEDIFF(_pre,_last,DAY)

 

Eyelyn9_1-1635494565300.png

 

 

If it is still not your expected,please show me what you want .

 

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

@Anonymous I really appreciate your help. When I try your latest measure on my actual data I still get the incorrect result.  Below is project A. COD date is the same as construction start date. When I use either of your two measures, I get a difference of 153 days when this should be zero (i.e. the COD date hasn't changed in the most recent two months). I hope that makes sense!

GJUDGE_0-1635496568300.png

 

Anonymous
Not applicable

Hi @GJUDGE ,

 

Please try:

Measure = 
var _pre=MAXX(FILTER(ALL('Table'),[Project]=MAX('Table'[Project]) && [Construction Start Date]<MAX('Table'[Construction Start Date])),[Construction Start Date])
return DATEDIFF(_pre,MAX('Table'[Construction Start Date]),DAY)

Eyelyn9_0-1635490601984.png

 


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

@Anonymous This almost gets me there! The only other complexity is that my actual data contains many months data. Using your measure it appears to be comparing the last and first dates rather than the last two months. is there any way to modify your measure?

lbendlin
Super User
Super User

please explain how you get to the 120.

@lbendlin In August, project A was planned to start construction on 01/01/2023. In September this date had slipped to 01/05/2023. I.e. it had moved back 120 days. 

Your sample data says that project A slipped to 2023-02-01.

 

 

@lbendlin You are completely right, I was misreading my own rows! So looking for a measure to calculate the 30 days difference, if you can assist?

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.