Historian Query

Hello,

I am trying to query a Historian for total kwh usage.

Every hour, the value changes as the khw is calculated every one hour. So, I think I have a chart like this

Hour 1 333
Hour 1 333
Hour 1 333
Hour 1 333
Hour 2 299
Hour 2 299
Hour 2 299
Hour 2 299
Hour 3 566
Hour 3 566
Hour 3 566

And so on…

I need to sum the new value for every hour for a day, so, the sum of 24 values. Is there a good way I could do this?

I’m using this sort of query right now for other parts:
dataSet = system.tag.queryTagHistory(paths=[‘MSWs/MSB_4/Energy_Incremental_Real_In_Last_Interval/Calculated’], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode=“Maximum”, returnFormat=‘Wide’)

thank you

You should be able to accomplish this with a two step process:
First, look into the following parameters on the queryTagHistory function:
Integer intervalHours - Allows you to specify the window interval in terms of hours, as opposed to using a specific return size.

Integer rangeHours - Allows you to specify the query range in hours, instead of using start and end date. Can be positive or negative, and can be used in conjunction with startDate or endDate.

You should be able to remove the returnsize=1 parameter, and instead switch to rangeHours=24 and intervalHours=1 (and only pass in an enddate parameter) and return the 24 values, 1 per hour, you’re looking for.

From there it should be fairly easy to loop through the resulting dataset if you’re familiar with Python. If not, I’d suggest taking a look at the Working with Datasets page on the documentation, and if you still have problems, post back here again.