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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
IEPMost
Helper III
Helper III

How to calculate daily average based on hourly data in M?

Hi guys,

 

hope you can help out, I didn´t find anything on this for Power Query...

 

seems pretty simple:

I have two columns [datetime] and [temperature] - for every hour on every day there is a temperature. Now I need to get the average of the temperature for a day. In other words: I want to reduce my rows so there is only one value for date.

 

One example:

 

Before:

10.01.20148,8
10.01.2014 01:006,2
10.01.2014 02:005
10.01.2014 03:004,4
10.01.2014 04:003
10.01.2014 05:002,2
10.01.2014 06:001,6
10.01.2014 07:001,6
10.01.2014 08:002
10.01.2014 09:002,2
10.01.2014 10:003,1
10.01.2014 11:003,9
10.01.2014 12:005,2
10.01.2014 13:006,3
10.01.2014 14:005,5
10.01.2014 15:005,2
10.01.2014 16:004,8
10.01.2014 17:003,8
10.01.2014 18:002,4
10.01.2014 19:001,6
10.01.2014 20:001,1
10.01.2014 21:000,6
10.01.2014 22:000,2
10.01.2014 23:000,1

 

After:

10.01. 20143,3336

 

Any help is much appreciated!!

 

Cheers:)

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @IEPMost 

 

first transform datetime to date and then apply a grouping on your date, averaging the degrees-column. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddFbCsUgDATQrRS/Q8nEaLVbKd3/Nm5BAxdGfz3k4eR5EvRUnKbwJKlJS6/8Px6KW/WjKkZkgwpBHuDiRD4oE5QBtphTB0Eq0bWnNhsS9O0k6NxOQISgThQ5LBrmSI8+DI8qyg9l37BGtHQpXLEhU2TBB0HfJmgaRGnYTEMXVRZEy1sO+hq+Pw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t, Degrees = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"Degrees", type number}}, "de-DE"),
    #"Extracted Date" = Table.TransformColumns(#"Changed Type",{{"DateTime", DateTime.Date, type date}}),
    #"Grouped Rows" = Table.Group(#"Extracted Date", {"DateTime"}, {{"Average", each List.Average([Degrees]), type number}})
in
    #"Grouped Rows"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

1 REPLY 1
Jimmy801
Community Champion
Community Champion

Hello @IEPMost 

 

first transform datetime to date and then apply a grouping on your date, averaging the degrees-column. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddFbCsUgDATQrRS/Q8nEaLVbKd3/Nm5BAxdGfz3k4eR5EvRUnKbwJKlJS6/8Px6KW/WjKkZkgwpBHuDiRD4oE5QBtphTB0Eq0bWnNhsS9O0k6NxOQISgThQ5LBrmSI8+DI8qyg9l37BGtHQpXLEhU2TBB0HfJmgaRGnYTEMXVRZEy1sO+hq+Pw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t, Degrees = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"Degrees", type number}}, "de-DE"),
    #"Extracted Date" = Table.TransformColumns(#"Changed Type",{{"DateTime", DateTime.Date, type date}}),
    #"Grouped Rows" = Table.Group(#"Extracted Date", {"DateTime"}, {{"Average", each List.Average([Degrees]), type number}})
in
    #"Grouped Rows"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors