# Kibana latest value aggregation pie chart

**URL:** <https://discuss.elastic.co/t/kibana-latest-value-aggregation-pie-chart/169312>\
**Category:** Kibana\
**Created:** [February 21, 2019, 12:23am UTC](https://discuss.elastic.co/t/kibana-latest-value-aggregation-pie-chart/169312 "2019-02-21T00:23:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaeNa](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@kaeNa](https://discuss.elastic.co/u/kaeNa)\
**Post date:** [February 21, 2019, 12:23am UTC](https://discuss.elastic.co/t/kibana-latest-value-aggregation-pie-chart/169312/1 "2019-02-21T00:23:22Z")

</div>

Imagine a service reports a `user_id` and a `country` on an event of a country change by a user. How possible to chart an aggregation on user count per country, considering that user should be counted towards the current (latest reported for this user\_id) country only.

For example, we have the following entries:  
// user\_id: 1, country: UK, @timestamp: 1  
// user\_id: 2, country: UK, @timestamp: 2  
// user\_id: 1, country: USA, @timestamp: 3  
// user\_id: 3, country: UK, @timestamp: 4

The results should be the following:  
// UK: 2  
// USA: 1

**If it's possible** , then how to visualise the result in a pie chart,  
If it's **not** possible, then the **bonus question** :

Imagine there's a way to report the current country stats into elk, how would you report it in order to get the desired pie chart?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [February 21, 2019, 10:19pm UTC](https://discuss.elastic.co/t/kibana-latest-value-aggregation-pie-chart/169312/2 "2019-02-21T22:19:25Z")

</div>

Hi,

To get that kind of aggregation in Kibana, you'll want a user-centric index that keeps the last-known country for each user updated as new events are generated. Take a look at a similar question I helped with: [Count Of Metric after Doing Top Hits](https://discuss.elastic.co/t/count-of-metric-after-doing-top-hits/169292/2)

---

<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:** [March 21, 2019, 10:19pm UTC](https://discuss.elastic.co/t/kibana-latest-value-aggregation-pie-chart/169312/3 "2019-03-21T22:19:29Z")

</div>

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