Forum Discussion
SamBrown17
Helper I
4 years agoHow to calculate Date diff with data setup
Hi Team, I have the example data below, I have a database full of record types which are jobs in my system, I want to calculate the average time or date difference between a set sequence of t...
- 4 years ago
SamBrown17 Right, it's the same principle but yours will look something like this:
Column = VAR __record = [record_id] VAR __type = [event_type] VAR __current = [created_at] VAR __currentStatus = [To (Status)] VAR __previous = IF(__type = "Job status updated", SWITCH(__currentStatus, "Scheduled",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = BLANK(),[created_at]), "Site Attended",MAXX(FILTER('Table',[record_id] = __record && [From (Status) = "Book" && [To (Status)] = "Scheduled",[created_at]) ) ) RETURN __current - __previous
mh2587
Super User
4 years agoVAR CurrentDate = CALCULATE ( MAX(Table[Created_at] ),
ALL( 'Table'[Record_ID] )
)
var LastDate = CALCULATE(
MAX(Table[Created_at]),
ALL( 'Table'[Record_ID] ),
Table[Created_at] < CurrentDate )
VAR DD = DATEDIFF ( LastDate,CurrentDate, DAY )
RETURN DD