How can use MEAN(average) aggregates filter value?

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}, "Weight" ) //... would return 5.58675


thank you

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() 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() function to return the mean value your looking for.

Filtered Mean on (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:
 if event.propertyName == 'data' or event.propertyName == 'filterValue':
	datasetIn = system.dataset.toPyDataSet(
	filterValue = event.source.filterValue
	data = [row['Float Column'] for row in datasetIn if row['Float Column'] > filterValue]
	event.source.mean = system.math.mean(data)


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

How to condition mean in expression?

thank you.

You can’t. That’s why I supplied you with a script and an example. :slight_smile:

1 Like

Ok i see. ^^
thank you.