Forum Discussion

Jodallen123's avatar
Jodallen123
Helper I
2 years ago
Solved

Total average of datediff

Hello,   I am trying to create a measure that calculates average handling time per project. My data looks something like this, it's a table with logs of status changes.     My current meas...
  • OwenAuger's avatar
    2 years ago

    Hi Jodallen123 

    Try this:

    PL handling time =
    AVERAGEX (
        VALUES ( 'logs'[Ordernumber] ),
        VAR minbookedmeeting =
            CALCULATE (
                MIN ( 'logs'[Created_date] ),
                'logs'[status_changed_to] = "B"
                    || 'logs'[status_changed_to] = "C"
            )
        VAR maxcustomerdone =
            CALCULATE (
                MAX ( 'logs'[Created_date] ),
                'logs'[status_changed_to] = "D"
                    || 'logs'[status_changed_to] = "E"
            )
        VAR datedifference = maxcustomerdone - minbookedmeeting
        RETURN
            datedifference
    )

     

    It's essentially the same code as you had, but wrapped in AVERAGEX ( VALUES (... ), ... )

    AVERAGEX (
        VALUES ( 'logs'[Ordernumber] ),
        <your original code>
    )

    This will compute the datedifference for each Ordernumber, then return the arithmetic mean of these values.

     

    For simplicity, I also suggest subtracting the dates rather than using DATEDIFF (they are both valid though).

     

    Does this work for you?

     

    Regards