Forum Discussion
vincenardo
4 years agoHelper I
Calculate Differance Between two dates, grouping by another field in data set.
In this dataset, I have rows of data that share the same 'PhaseID'. I want to calculate the differance (in days) between the first 'ScheduledStartDate' and the last 'ScheduledCompleteDate' for each r...
- 4 years ago
Hi vincenardo
You can try this measure to get diff between ScheduledStartDate & ScheduledCompleteDate.
diff = var _min=CALCULATE(MIN('Table'[ScheduledStartDate]),ALLEXCEPT('Table','Table'[PhaseID])) var _max=CALCULATE(MAX('Table'[ScheduledCompleteDate]),ALLEXCEPT('Table','Table'[PhaseID])) return DATEDIFF(_min,_max,DAY)+1and if you want to exclude weekends in the calculation, then add a calendar table, and use the measure bellow
diff = var _min=CALCULATE(MIN('Table'[ScheduledStartDate]),ALLEXCEPT('Table','Table'[PhaseID])) var _max=CALCULATE(MAX('Table'[ScheduledCompleteDate]),ALLEXCEPT('Table','Table'[PhaseID])) return CALCULATE(COUNTROWS('Calendar'),DATESBETWEEN('Calendar'[Date],_min,_max),'Calendar'[Isweekday]<>7&&'Calendar'[Isweekday]<>1)result
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
v-xiaotang
4 years agoCommunity Support
Hi vincenardo
You can try this measure to get diff between ScheduledStartDate & ScheduledCompleteDate.
diff =
var _min=CALCULATE(MIN('Table'[ScheduledStartDate]),ALLEXCEPT('Table','Table'[PhaseID]))
var _max=CALCULATE(MAX('Table'[ScheduledCompleteDate]),ALLEXCEPT('Table','Table'[PhaseID]))
return
DATEDIFF(_min,_max,DAY)+1
and if you want to exclude weekends in the calculation, then add a calendar table, and use the measure bellow
diff =
var _min=CALCULATE(MIN('Table'[ScheduledStartDate]),ALLEXCEPT('Table','Table'[PhaseID]))
var _max=CALCULATE(MAX('Table'[ScheduledCompleteDate]),ALLEXCEPT('Table','Table'[PhaseID]))
return
CALCULATE(COUNTROWS('Calendar'),DATESBETWEEN('Calendar'[Date],_min,_max),'Calendar'[Isweekday]<>7&&'Calendar'[Isweekday]<>1)
result
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.