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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BotBot1
Helper III
Helper III

Last and average between dates

Hi,

I am trying to replicate the following table in Power BI but am struggling with writing the DAX for calculating some of the columns.

BotBot1_0-1676654880600.png

I cannot seem to get the last formal inspection date or the two last columns to work as when I change the format to latest date for the last inspection date column it says all of the last inspection dates for all projects were 31/12/2029.

Here is what it currently looks like, with the 'Last Formal Inspection Date' currently showing all inspection dates.

BotBot1_1-1676655315702.png

I have the following attempted DAX with the variable names for getting the days between inspections to try and get the last two average columns from the original Excel screenshot:

 

AvgDaysBetweenFormalInspections = 
VAR CurrentProject = ALL(Project[ProjectName])
VAR CurrentDate = ALL('Date of Inspection'[date])
VAR LastInspection = 
    CALCULATE(
        MAX('Date of Inspection'[date]),
        FILTER(
            ALL(Project),
            Project[ProjectName] = CurrentProject &&
            ALL('Date of Inspection'[date]) < CurrentDate
        )
    )
RETURN IF (LastInspection = BLANK(), BLANK(), CurrentDate - LastInspection)

 

This currently doesn't work as it says 'a table of multiple values was supplied where a single value was expected'. 

I'm not sure if this is because I am live connected or that it is because I am using 'ALL', but if anyone can assist me on any of the 3 columns it would be hugely appreciated. 

Thank you.

2 REPLIES 2
FreemanZ
Super User
Super User

hi @BotBot1 

try like:

AvgDaysBetweenFormalInspections = 
VAR CurrentProject = 
MAX(Project[ProjectName])
VAR CurrentDate = 
MAX('Date of Inspection'[date])
VAR LastInspection = 
    CALCULATE(
        MAX('Date of Inspection'[date]),
        FILTER(
            ALL(Project),
            Project[ProjectName] = CurrentProject &&
            'Date of Inspection'[date]< CurrentDate
        )
    )
RETURN 
IF(
    LastInspection = BLANK(), 
    BLANK(), 
    CurrentDate - LastInspection
)

Hi,

 

Unfortunately it didn't work, it is now returning all rows as 30/12/1899.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors