Get average but filter values

Hi,
I am currently trying to display the average (grouped by time (1m)) of some values via grafana, pings to some hosts to be exact. I want to filter values that are too far off from the average to filter out values, where the pinging host itself has problems.
e.g.
host1 says 15ms ping to target
host2 says 20ms ping to target
host3 say 500ms ping to target
-> calculate the average from host1 and host2 without host3 for this value

I want to do this on a per-value-base, so that a host is not excluded completely just because two pings were far off (e.g. due to a short network outage or similar). How can I achieve this?

It kind of sounds like you want percentile?

Can you check that out and let me know if this is what you’re after?

https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#percentile