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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

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

 

 

1 ACCEPTED SOLUTION
JarroVGIT
Resident Rockstar
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:

image.png

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 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
dax
Community Support
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
Resident Rockstar
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:

image.png

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 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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! 🙂

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.