Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Calculating maximum time between two records

Hello, I have a dashboard that I use for statistics on incident reports. I use a measure to calculate the working days between today and the last incident posted in my database. Here's the measure...
  • timalbers's avatar
    timalbers
    1 year ago

    Yea my bad, as _incidents is a virtual table inside the same expression, DAX expects column references without the table name.

    If you want to also include the time between the last incident and today, we will have to add some more variables inside the measure. Just append this to the existing variables and replace the RETURN row:

    VAR last_incident = MAXX( FILTER( Incident, Incident[TypeAccident] = "AT" ), Incident[DateAndTime] )
    
    VAR last_vs_today =
        COUNTROWS(
            FILTER(
                Dates,
                Dates[Date] > last_incident &&
                Dates[Date] <= TODAY() &&
                WEEKDAY( Dates[Date], 2 ) < 6
            )
        )
    
    RETURN MAX( _max, last_vs_today )