# How can use MEAN(average) aggregates filter value?

**URL:** <https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687>\
**Category:** Ignition\
**Created:** [February 28, 2020, 1:39am UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687 "2020-02-28T01:39:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![soontosr](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@soontosr](https://forum.inductiveautomation.com/u/soontosr)\
**Post date:** [February 28, 2020, 1:39am UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/1 "2020-02-28T01:39:05Z")

</div>

how can use MEAN aggregates filter value?

Ex. Mean Weight \> 2.0  
that. Mean 3 row., row is value “1.287” not Mean

| **ProductCode** | **Quantity** | **Weight** |
| --- | --- | --- |
| BAN\_002 | 380 | 3.243 |
| BAN\_010 | 120 | 9.928 |
| APL\_000 | 125 | 1.287 |
| FWL\_220 | 322 | 7.889 |

**Code Snippet**

`mean({Root Container.Table.data}, ` `"Weight"` `) ` `//... would return 5.58675`

![mean](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6a60dda8257d59f8da6746bbedfacd24a2e40c6b.jpeg)

thank you

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [February 28, 2020, 4:03pm UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/2 "2020-02-28T16:03:11Z")

</div>

Using the Mean expression value I don’t believe you will be able to exclude values. I believe for what your looking for you would have to create a script instead of just using an expression. Or if your pulling the dataset through a query you could have an extra query feeding a custom property that isn’t displayed on the page. If you did the custom property, after limiting it down then you could use the MEAN() expression.

If you need to script it, you have a few options. You can loop through your data and store the row indexes you want to remove then use the [system.dataset.deleteRows()](https://docs.inductiveautomation.com/display/DOC80/system.dataset.deleteRows) function to create your new data set and write it into a custom property then do your mean function. For this though you would need a custom property to hold your filtered dataset and one to run your mean function from.

What I would do though is loop through your dataset and create a list of the values you want. Then use the [system.math.mean()](https://docs.inductiveautomation.com/display/DOC80/system.math.mean) function to return the mean value your looking for.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 28, 2020, 4:35pm UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/3 "2020-02-28T16:35:42Z")

</div>

[Filtered Mean on Table\_2020-02-28\_1127.zip](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/acc8869c291c2595a27553f1e30a7d2090da9d28.zip) (19.8 KB)

This example gives a mean value of the Float Column based on a values greater than the filter value.

- Power Table has two custom properties: _filterValue_ and _mean_.
- In the Power Tablews propertyChange script:

```python
 if event.propertyName == 'data' or event.propertyName == 'filterValue':
	datasetIn = system.dataset.toPyDataSet(event.source.data)
	filterValue = event.source.filterValue
	data = [row['Float Column'] for row in datasetIn if row['Float Column'] > filterValue]
	event.source.mean = system.math.mean(data)

```

---

<div class="post-metadata">

**Author:** ![soontosr](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@soontosr](https://forum.inductiveautomation.com/u/soontosr)\
**Post date:** [February 28, 2020, 5:18pm UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/4 "2020-02-28T17:18:37Z")

</div>

ex.  
col1  
1  
2  
3

normal mean(average) col1 is = 2  
condition mean(average) col1 \> 1 is = 2.5

How to condition mean in expression?

thank you.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 28, 2020, 5:21pm UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/5 "2020-02-28T17:21:22Z")

</div>

> [@soontosr](#):
>
> How to condition mean in expression?

You can't. That's why I supplied you with a script and an example. 🙂

---

<div class="post-metadata">

**Author:** ![soontosr](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@soontosr](https://forum.inductiveautomation.com/u/soontosr)\
**Post date:** [February 28, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/how-can-use-mean-average-aggregates-filter-value/32687/6 "2020-02-28T17:27:12Z")

</div>

Ok i see. ^^  
thank you.
