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
samba_axe
New Member

How do I sum four values (quarter hours) to get a running hourly sum?

Hello all!

I am new to Power BI and I am finding that the simplest things in Excel are a bear in PBI.

I have 15 minute data from a flow/heat meter that I need to sum every hour to give me the hourly kiloWatt hours.

In Excel I would simply =sum(x1,x2,x3,x4) then skip four spaces and do that again, all the way down the column.

How can I do this in Power BI and keep it all referenced to the same date and the proper hour? Below is an example from Excel and in it I am summing (15:15,15:30,15:45,16:00) and displaying the data in the same row as 16:00 under kWh. Any suggestings please?

 

datetimekW 15 minT inT outflowkWh
15/07/201515:15:000.7579.6871.113.6 
15/07/201515:30:000.8579.9671.723.75 
15/07/201515:45:000.9580.2472.333.9 
15/07/201516:00:000.9780.6272.833.913.52
15/07/201516:15:000.9780.8772.613.9 
15/07/201516:30:000.9680.8572.613.76 
15/07/201516:45:000.9580.8372.613.62 
15/07/201517:00:00265.8478.5171.5632.51268.72
15/07/201517:15:00232.278.1771.2231.75 
15/07/201517:30:00233.2978.370.532.31 
15/07/201517:45:00233.2978.2870.530.36 
15/07/201518:00:00237.6378.6970.7829.93936.41
15/07/201518:15:00239.878.7470.530.17 
15/07/201518:30:00237.6378.8770.8329.8 
15/07/201518:45:00240.8978.6870.6130.7 
15/07/201519:00:00243.0678.7170.8929.57961.38
15/07/201519:15:00246.3178.7270.530.36 
15/07/201519:30:00244.1478.4370.0630.69 
15/07/201519:45:00246.3178.4770.4530.19 
15/07/201520:00:00246.3178.2870.2830.24983.07
15/07/201520:15:00235.4678.6970.8928.96 
15/07/201520:30:00233.2979.1371.4529.12 
13 REPLIES 13
ankitpatira
Community Champion
Community Champion

@samba_axe Here's what you can do. I created sample data like your scenario. In power bi desktop go to query editor, select your time column, under transform tab under Date & Time Column select Time dropdown and click Hour. This will extract hour out of your date time. Then finally group by that hour by going to Group By.

 

1.png2.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Sean
Community Champion
Community Champion

@ankitpatira I think he says he wants to add 15:15+15:30+15:45+16:00 (implying these are end times)

 

So maybe he needs to first add a custom start time column (end time - 15min) and then Group By

ankitpatira
Community Champion
Community Champion

@Sean Nice one. Thanks for pointing out.

Maybe...but I need to make sure that the 15 minute selections are kept in chronoligical order and bound to their proper hour, day, month and year.

Here's an example code:

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type text}, {"time", type time}, {"kW 15 min", type number}}),
#"Extracted Hour" = Table.TransformColumns(#"Changed Type",{{"time", Time.Hour}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Extracted Hour",{{"time", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"date", "time"}, {{"kWh", each List.Sum([kW 15 min]), type number}})
in
#"Grouped Rows"

 

I assumed the first 3 columns are the inputs, and they're coming from an Excel table, you can alter it.

Essentially there are 2 steps:

  • Extracting hour from the time column
    • Untitled.png
  • Group by date&time columns with Sum aggregate
    • Untitled.png
    • Untitled.png

 

I hope this helps

 

(One catch, this will show the sum of 15:00, 15:15, 15:30, 15:45 unlike your example 😕 otherwise if you want it to show exactly what you wanted, this would be a little bit more complicated (needs to subtract 1 second before you extracted the hour))

Thanks for that but where do I enter that code? I assume the code must be entered before I group the cells?

I assume that because i tried to group them and the resulting column gave me the same numbers I had before.

It looks like we are on the right track and I can see what Sean means about subtracting on to end on the hour.

Sorry but I am a totaly noob on Power BI. I just got on yesterday. I need to set it up for a real time display for energy meter data and I need to convert our 15 minute readings into kilowatt hours to do so. Easy as pie in Excel but this is a new game for me.

hi sean! can you help me out i actually need to do the exact same thing but on excel with a dataset of a year.

Hello and thank you for helping. Yes, I need to sum the 4 parts of an hour and it is not actually the hour I am summing, I want to sum the power data that is taken every 15 minutes and I want to sum those to give a value for that hour. The end time should always be on the hour, not at 15, 30 or 45, only on :00.

Just like below

datetimekW 15 minT inT outflowkWh
15/07/201515:15:000.7579.6871.113.6 
15/07/201515:30:000.8579.9671.723.75 
15/07/201515:45:000.9580.2472.333.9 
15/07/201516:00:000.9780.6272.833.913.52
Sean
Community Champion
Community Champion

That's exactly what I meant. Before you apply the steps outlined by Ankit you need to change the hour in the 4th value you want to sum. The 16 needs to be 15 so you can Group By correctly.
And what I was suggesting was a custom start column that would deduct 15 min from each time.
This way every 4th value you will be grouping will match the previous 3 and you'll get the right kW sum.

In the end it should look like this one i did on Excel

 

datetimekW 15 minT inT outflowkWh
15/07/201515:15:000.7579.6871.113.6 
15/07/201515:30:000.8579.9671.723.75 
15/07/201515:45:000.9580.2472.333.9 
15/07/201516:00:000.9780.6272.833.913.52
15/07/201516:15:000.9780.8772.613.9 
15/07/201516:30:000.9680.8572.613.76 
15/07/201516:45:000.9580.8372.613.62 
15/07/201517:00:00265.8478.5171.5632.51268.72
15/07/201517:15:00232.278.1771.2231.75 
15/07/201517:30:00233.2978.370.532.31 
15/07/201517:45:00233.2978.2870.530.36 
15/07/201518:00:00237.6378.6970.7829.93936.41
15/07/201518:15:00239.878.7470.530.17 
15/07/201518:30:00237.6378.8770.8329.8 
15/07/201518:45:00240.8978.6870.6130.7 
15/07/201519:00:00243.0678.7170.8929.57961.38
15/07/201519:15:00246.3178.7270.530.36 
15/07/201519:30:00244.1478.4370.0630.69 
15/07/201519:45:00246.3178.4770.4530.19 
15/07/201520:00:00246.3178.2870.2830.24983.07
15/07/201520:15:00235.4678.6970.8928.96 
15/07/201520:30:00233.2979.1371.4529.12 
15/07/201520:45:00235.4679.9671.2228.77 
15/07/201521:00:00236.5579.7471.9529.4940.76
Sean
Community Champion
Community Champion

@samba_axe how do you ultimately plan visualize this in PBI?

 

You don't really need to do Group By in the Query Editor.

 

After you import your data just create a Calculated Column

 

Calculated Column  = HOUR('Table'[time]-(0.25/24))

 

Then create a Matrix like this...

Time - QE.png

Oh sorry,

To visualize it will be likely graphed along with the other meters on campus relative to the full load. In other words, as a portion of the whole to show the relative energy/flow of each building on campus.

Ah ok..that makes some sense to me. Thanks for that. I will give it a try soon and see how it goes. I have a bit on today so it may take a while. I thank you all for your help. Cross fingers!

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.