Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Average basis hour duration from timestamp

Hi All

 

I have data with timestamp like below with single instance for each hour of day/date and i want to calculate average value for last 40 hours for each instance/hour. Any helps will be appreciated.

 

TimestampValue
1/1/2018 0:009621
1/1/2018 1:007240
1/1/2018 2:001826
1/1/2018 3:001722
1/1/2018 4:004110
1/1/2018 5:003745
1/1/2018 6:004316
1/1/2018 7:004479
1/1/2018 8:003008
1/1/2018 9:002626
1/1/2018 10:008620
1/1/2018 11:001571
1/1/2018 12:001607
1/1/2018 13:00298
1/1/2018 14:003629
1/1/2018 15:009757
1/1/2018 16:007289
1/1/2018 17:00105
1/1/2018 18:008406
1/1/2018 19:001756
1/1/2018 20:002217
1/1/2018 21:007859
1/1/2018 22:001101
1/1/2018 23:009790
2/1/2018 0:008777
2/1/2018 1:008141
2/1/2018 2:009291
2/1/2018 3:009015
2/1/2018 4:009150
2/1/2018 5:002421
2/1/2018 6:003708
2/1/2018 7:001216
2/1/2018 8:002443
2/1/2018 9:006619
2/1/2018 10:003490
2/1/2018 11:009510
2/1/2018 12:003688
2/1/2018 13:005479
2/1/2018 14:00829
2/1/2018 15:008393
2/1/2018 16:006392
2/1/2018 17:00825
2/1/2018 18:005675
2/1/2018 19:005752
2/1/2018 20:00695
2/1/2018 21:001950
2/1/2018 22:008079
2/1/2018 23:00460
3/1/2018 0:009310

 

 

  • Took me longer than I would like to admit πŸ˜› Anyway, I solved it, by creating a calculated column with the following formula:

    Last48Hours = AVERAGEX(FILTER(Table1, Table1[Timestamp] <= EARLIER(Table1[Timestamp]) && Table1[Timestamp] > EARLIER(Table1[Timestamp])-40/24), Table1[Value])

    The reason it took me longer than I expected was both 'how to add hours to a datetime'  and also the double filter. Anyway, this will result in the following table:

    This was fun, hope it helped πŸ™‚

    Kind regards

    Djerro123

    -------------------------------

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Kudo's are welcome πŸ™‚

3 Replies

  • dax's avatar
    dax
    Community Support

    Hi dynamic2019,

    You could try to refer to my sample to see whether it work or not.

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • JarroVGIT's avatar
    JarroVGIT
    Resident Rockstar

    Took me longer than I would like to admit πŸ˜› Anyway, I solved it, by creating a calculated column with the following formula:

    Last48Hours = AVERAGEX(FILTER(Table1, Table1[Timestamp] <= EARLIER(Table1[Timestamp]) && Table1[Timestamp] > EARLIER(Table1[Timestamp])-40/24), Table1[Value])

    The reason it took me longer than I expected was both 'how to add hours to a datetime'  and also the double filter. Anyway, this will result in the following table:

    This was fun, hope it helped πŸ™‚

    Kind regards

    Djerro123

    -------------------------------

    If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

    Kudo's are welcome πŸ™‚

    • Anonymous's avatar
      Anonymous
      Not applicable

      Both the answers work as absolute solution to my problem however accepting the first answer as solution for below 2 reasons -

       

      1. ofcourse the first solution.

      2. It works on existing timestamp column instead of additional helper column.

       

      Tons of thanks to both! πŸ™‚