Forum Discussion
Anonymous
3 years agoNot applicable
Average Days Between Inspections
Hi, I am trying to get the average days between inspection dates. Below is a breakdown of current dates by project (with blue and green dots being 2 different projects). Below is my attempted...
- 3 years ago
Anonymous
Please tryAverageDaysBetweenInspections = AVERAGEX ( SUMMARIZE ( 'HSE Inspection', Project[ProjectName], 'Date of Inspection'[date] ), VAR CurrentDate = 'Date of Inspection'[date] VAR CurrentProjectTable = CALCULATETABLE ( SUMMARIZE ( 'HSE Inspection', Project[ProjectName], 'Date of Inspection'[date] ), ALL ( 'Date of Inspection'[date] ) ) VAR TableBefore = FILTER ( CurrentProjectTable, 'Date of Inspection'[date] < CurrentDate ) VAR PreviousDate = MAXX ( TableBefore, 'Date of Inspection'[date] ) RETURN IF ( NOT ISEMPTY ( TableBefore ), INT ( CurrentDate - PreviousDate ) ) )
johnt75
3 years agoSuper User
How about
DaysBetweenInspectionsALL =
VAR CurrentProject =
SELECTEDVALUE ( Project[ProjectName] )
VAR CurrentDate =
SELECTEDVALUE ( 'Date of Inspection'[date] )
VAR LastInspectionDate =
CALCULATE (
MAX ( 'Date'[Date] ),
REMOVEFILTERS ( Project ),
Project[ProjectName] = CurrentProject,
'Date of Inspection'[date] < CurrentDate
)
RETURN
IF (
LastInspectionDate = BLANK (),
BLANK (),
INT ( CurrentDate - LastInspectionDate )
)
tamerj1
3 years agoCommunity Champion
Seems like 'Date of Inspection' is at the many side od the relationship.
In this case either to CROSSFILTER-BOTH the relationship or MAXX ( RELATEDTABLE ) like
DaysBetweenInspectionsALL =
VAR CurrentProject =
SELECTEDVALUE ( Project[ProjectName] )
VAR CurrentDate =
SELECTEDVALUE ( 'Date of Inspection'[date] )
VAR LastInspectionDate =
CALCULATE (
MAX ( 'Date'[Date] ),
FILTER (
ALL ( Project ),
Project[ProjectName] = CurrentProject
&& MAXX ( RELATEDTABLE ( 'Date of Inspection' ), 'Date of Inspection'[date] ) < CurrentDate
)
)
RETURN
IF (
LastInspectionDate = BLANK (),
BLANK (),
INT ( CurrentDate - LastInspectionDate )
)