Getting the Avg Days, Avg Hours, Avg Minutes

Options

Hello. May I ask for your help in getting the average days or average hours or average minutes between 2 columns of date + timestamp data?

The thing is, the average could be 'days', 'hours' or 'minutes', depending on the values of the 2 data columns, so we want to show the output similar to a timestamp format to be precise, since we could not determine or put unit of measure whether the output is in 'days' or 'hours' or 'minutes'.

See below example of output. If the output is 17 hours, we want to see that in

'DAYS HOURS:MINUTES' or somehow similar to '0 17:00'. But if you have a different approach for this one, please let us know. Thank you

Tagged:

Best Answers

  • DavidChurchman
    Answer ✓
    Options

    I think you want something like:

    CONCAT(

    DATEDIFF(QB-Closed-Date, QB-Created-Date), ' ', //days

    HOUR(TIMEDIFF( QB-Closed-Date, QB-Created-Date)), ':', //hours

    MINUTE(TIMEDIFF( QB-Closed-Date, QB-Created-Date)) //minutes

    )

    (Adapted from @JaySethi in this discussion)

    Please 💡/💖/👍/😊 this post if you read it and found it helpful.

    Please accept the answer if it solved your problem.

  • ST_-Superman-_
    Answer ✓
    Options

    @Zel

    The issue that you will run into with @DavidChurchman solution is that the field will then be a text value and you will not be able to get an average.

    I would use something like this to get the number of seconds between the two values.

    You can then find the average of that numeric value. Then the issue becomes one of converting the average seconds between the two values to the format you want.


    “There is a superhero in all of us, we just need the courage to put on the cape.” -Superman

Answers

  • ST_-Superman-_
    Options

    Hi @Zel

    What do your input datasets look like? Also, are you wanting the ETL to calculate the Averages for you, or are you going to find the average at the card level?


    “There is a superhero in all of us, we just need the courage to put on the cape.” -Superman
  • Zel
    Zel Member
    Options

    hi @ST_-Superman-_!

    ETL or card level will do, as long as we could come up with the solution on how to display the average and its format - as mentioned in the original post.

    The 2 columns look like this: QB-Created Date and QB-Closed Date.

  • DavidChurchman
    Answer ✓
    Options

    I think you want something like:

    CONCAT(

    DATEDIFF(QB-Closed-Date, QB-Created-Date), ' ', //days

    HOUR(TIMEDIFF( QB-Closed-Date, QB-Created-Date)), ':', //hours

    MINUTE(TIMEDIFF( QB-Closed-Date, QB-Created-Date)) //minutes

    )

    (Adapted from @JaySethi in this discussion)

    Please 💡/💖/👍/😊 this post if you read it and found it helpful.

    Please accept the answer if it solved your problem.

  • ST_-Superman-_
    Options

    @Zel

    all of your Closed Dates are actually occurring prior to the open date? From your screenshot, all of the elapsed times will be negative.


    “There is a superhero in all of us, we just need the courage to put on the cape.” -Superman
  • ST_-Superman-_
    Answer ✓
    Options

    @Zel

    The issue that you will run into with @DavidChurchman solution is that the field will then be a text value and you will not be able to get an average.

    I would use something like this to get the number of seconds between the two values.

    You can then find the average of that numeric value. Then the issue becomes one of converting the average seconds between the two values to the format you want.


    “There is a superhero in all of us, we just need the courage to put on the cape.” -Superman