# Percentile ranks return wrong value

**URL:** <https://discuss.elastic.co/t/percentile-ranks-return-wrong-value/223755>\
**Category:** Elasticsearch\
**Created:** [March 16, 2020, 12:44pm UTC](https://discuss.elastic.co/t/percentile-ranks-return-wrong-value/223755 "2020-03-16T12:44:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yevhen\_Baidiuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yevhen_baidiuk/32/57956_2.png) [@Yevhen\_Baidiuk](https://discuss.elastic.co/u/Yevhen_Baidiuk)\
**Post date:** [March 16, 2020, 12:44pm UTC](https://discuss.elastic.co/t/percentile-ranks-return-wrong-value/223755/1 "2020-03-16T12:44:39Z")

</div>

I read about "Percentiles Aggregation" and know already about "relative error".  
In my case, I have to calculate correctly.  
I have 45 values greater than 0.4  
and 1 values smaller than 0.4  
So correct return percentile have to be (1\45\*100) =2.2222,  
but I get **"0.4": 1.6760828741290288**.

How is it possible to calculate the correct values?  
My Current request lool like

I read [here](https://github.com/elastic/elasticsearch/issues/26156) that max aggregation can solve the issue but I can not apply it.  
`{ "size": 0, "query": { "bool": { "must": [{ "query_string": { "query": "status:R OR status:Q OR status:P", "fields": [], "type": "best_fields", "default_operator": "or", "max_determinized_states": 10000, "enable_position_increments": true, "fuzziness": "AUTO", "fuzzy_prefix_length": 0, "fuzzy_max_expansions": 50, "phrase_slop": 0, "analyze_wildcard": true, "escape": false, "auto_generate_synonyms_phrase_query": true, "fuzzy_transpositions": true, "boost": 1 } }, { "range": { "final_date": { "from": 1577836800000, "to": 1583020800000, "include_lower": true, "include_upper": false, "format": "epoch_millis", "boost": 1 } } } ], "adjust_pure_negative": true, "boost": 1 } }, "aggregations": { "terms": { "terms": { "field": "station_code.keyword", "size": 300, "min_doc_count": 1, "shard_min_doc_count": 0, "show_term_doc_count_error": false, "order": { "_key": "asc" } }, "aggregations": { "histogram": { "date_histogram": { "field": "final_date", "format": "epoch_millis", "interval": "1M", "offset": 0, "order": { "_key": "asc" }, "keyed": false, "min_doc_count": 0, "extended_bounds": { "min": 1577836800000, "max": 1582934400000 } }, "aggregations": { "aggregation": { "percentile_ranks": { "field": "value", "values": [0.4], "keyed": true, "tdigest": { "compression": 100 } } } } } } } } }`  
Thanks for response if any )

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 13, 2020, 12:56pm UTC](https://discuss.elastic.co/t/percentile-ranks-return-wrong-value/223755/2 "2020-04-13T12:56:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
