Adding multiple historical data together

I was trying to add some historical data of the flows to calculate total flow. I know total flow is calculated by adding each flow at a time. How do I add them so that I get the historical data of total flow so that I can display it in report? Thanks

  1. Where is it stored?
  2. In what units is it stored (flowrate (L/s), flow volume (litres), etc.)?

The easiest way might be to add an historized expression tag that sums up your partial flows.

All the flows are stored in Tag Historical Provider. The flowrate unit is same for all flows. I just need to add the flows and the total flowrate will also be same unit.

I did that. I created new expression tag and added all the flows together but it wont show/add the data from the past. It only shows the data from the time I configured tag history to the new totalflow tag.

The flowrate unit is same for all flows. I just need to add the flows and the total flowrate will also be same unit.

You can't total flowrates. 5 L/minute for one minute and 3 L/minute for another minute doesn't give you 8 L/minute. You can average them though.
You can total flows. This would be L (litres) or whatever your units are.

  1. Is the flow data cumulative (e.g. 10, 12, 14, 16, ...) or incremental (e.g., 2, 2.1, 2, 1.9, etc.).

If you need data from before, you can use queryTagHistory and do the calculations yourself:

tags = system.tag.queryTagHistory(paths)
tags = system.dataset.toPyDataSet(tags)
total_flow = [
	{
		'timestamp': row[0],
		'value': sum(row[1:])
	} for row in tags
]

If the presence of None is possible in your data, you can use this instead, but you might not get the results you want:

total_flow = [
	{
		'timestamp': row[0],
		'value': reduce(lambda x, y: (x or 0) + (y or 0), row[1:])
	} for row in tags
]

I meant to add flowrate at certain time for different flowmeters. Lets say for two flowmeters, if one is 5 and other is 3 during that time, I can add it to 8 units as the total flow during that time. I want to do that for multiple flowmeters.

Thanks, I will try to use this and see if I can do it.

Another way I am trying is to import each flow in the report and add them together in a column and export the total value in excel. Since I just need a report of this flow, that should do it.
I am also thinking of creating a database table with all the flows and a new column with their sum just in case for the future.