# Adding multiple historical data together

**URL:** <https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461>\
**Category:** Ignition\
**Created:** [March 22, 2022, 3:02pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461 "2022-03-22T15:02:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashants](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@prashants](https://forum.inductiveautomation.com/u/prashants)\
**Post date:** [March 22, 2022, 3:02pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/1 "2022-03-22T15:02:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 22, 2022, 3:35pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/2 "2022-03-22T15:35:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 3:42pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/3 "2022-03-22T15:42:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prashants](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@prashants](https://forum.inductiveautomation.com/u/prashants)\
**Post date:** [March 22, 2022, 3:46pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/4 "2022-03-22T15:46:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prashants](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@prashants](https://forum.inductiveautomation.com/u/prashants)\
**Post date:** [March 22, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/5 "2022-03-22T15:51:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 22, 2022, 3:52pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/6 "2022-03-22T15:52:42Z")

</div>

> 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.).

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 22, 2022, 3:56pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/7 "2022-03-22T15:56:14Z")

</div>

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

```python
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:

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

```

---

<div class="post-metadata">

**Author:** ![prashants](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@prashants](https://forum.inductiveautomation.com/u/prashants)\
**Post date:** [March 22, 2022, 4:04pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/8 "2022-03-22T16:04:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prashants](https://avatars.discourse-cdn.com/v4/letter/p/a87d85/32.png) [@prashants](https://forum.inductiveautomation.com/u/prashants)\
**Post date:** [March 22, 2022, 6:02pm UTC](https://forum.inductiveautomation.com/t/adding-multiple-historical-data-together/57461/9 "2022-03-22T18:02:26Z")

</div>

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.
