Forum Discussion
Average Days Between Inspections
- 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 ) ) )
Try removing the SELECTEDVALUE from the filter and casting the result as an int
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
&& 'Date of Inspection'[date] < CurrentDate
)
)
RETURN
IF (
LastInspectionDate = BLANK (),
BLANK (),
INT ( CurrentDate - LastInspectionDate )
)
- Anonymous3 years agoNot applicable
Hi johnt75,
Thank you for this. It is currently saying "cannot find name [date]" for the LastInspectionDate variable! Can this be fixed?
- johnt753 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 ) )- tamerj13 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 ) likeDaysBetweenInspectionsALL =
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 )
)