# Storing pre-aggregated data

**URL:** <https://discuss.elastic.co/t/storing-pre-aggregated-data/160667>\
**Category:** Elasticsearch\
**Created:** [December 13, 2018, 4:55am UTC](https://discuss.elastic.co/t/storing-pre-aggregated-data/160667 "2018-12-13T04:55:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben.zeghers](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@ben.zeghers](https://discuss.elastic.co/u/ben.zeghers)\
**Post date:** [December 13, 2018, 4:55am UTC](https://discuss.elastic.co/t/storing-pre-aggregated-data/160667/1 "2018-12-13T04:55:00Z")

</div>

I have a data set that I'd like to add to Elasticsearch so that we can build visualizations with it in Kibana. The problem I am running into is that since the data is pre-aggregated average aggregations I do on this data are incorrect since they do not take into account the quantity. Here is a simplified sample of my data:

```
+-------+-------+-------------+--------------+---------------+
| Month | Store | Total Sales | Average Sale | Quantity Sold |
+-------+-------+-------------+--------------+---------------+
| Jan | A | $1000 | $100 | 10 |
| Jan | B | $880 | $80 | 11 |
| Feb | A | $375 | $75 | 5 |
| Feb | B | $800 | $40 | 20 |
+-------+-------+-------------+--------------+---------------+

```

If I do an average of the average sale column I would get $74 ((100+80+75+40)/4). The result I would like to see would take into account the quantity and I would get $66 ((100×10+80×11+75×5+40×20)/(10+11+5+20)).

Is there a way to store pre-aggregated data like this in Elasticsearch so that aggregations will work correctly similar to the way the rollups work?

---

<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:** [January 10, 2019, 4:55am UTC](https://discuss.elastic.co/t/storing-pre-aggregated-data/160667/2 "2019-01-10T04:55:05Z")

</div>

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