Tag Historian Query Aggregation Mode - Range

Can anyone help me understand the following behavior when attempting to use the range aggregation mode in the reporting module with a tag historian query? The attached image is a comparison of the same data & time range, one with the aggregation mode set as Closest Value, and the other set as Range. The markups in red is what I would have expected the data to be.

In case this helps anyone else, the solution i totally didn't use chatGPT to help with is as follows:

	import java
	import jarray
	# Get the original dataset
	oldSet = data['tag_history'].getCoreResults()
	ds = system.dataset.toPyDataSet(oldSet)
	column_names = jarray.array(ds.getColumnNames(), java.lang.String)
	# Create a list to hold the new data rows
	new_rows = []
	# Iterate over the rows of the original dataset
	for i, row in enumerate(ds):
	    # Check if the current row is the first row
	    if i == 0:
	        # Create a new list to hold the modified row values
	        new_row = [row[0]]
	        # Iterate over the columns of the current row
	        for j in range(1, len(row)):
	            # Calculate the difference between the current and previous row value
	            diff = row[j] - ds[i-1][j]
	            # Append the modified value to the new row list
	        # Append the modified row to the new data list
	# Create the new dataset with the modified data
	new_ds = system.dataset.toDataSet(column_names, new_rows)
	data['Differential'] = new_ds

This then gives the result I was expecting the Range Aggregation Mode to result in

1 Like