# Pie chart with filtering

**URL:** <https://discuss.elastic.co/t/pie-chart-with-filtering/290271>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [November 26, 2021, 10:24am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271 "2021-11-26T10:24:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thenotoriousciu](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@thenotoriousciu](https://discuss.elastic.co/u/thenotoriousciu)\
**Post date:** [November 26, 2021, 10:24am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271/1 "2021-11-26T10:24:30Z")

</div>

Hello, everyone.  
I am trying to create a pie-chart based on the below data, but I am pretty sure that it can only be don with Vega, not with a regular pie-chart. However, I thought I could ask this question, see if anyone can help.  
So, for the following data:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/7/577496f97a3872d9c2802163d713d6a4aba29c41.png)

I would like to have a pie-chart with the following results:

![image](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b24e808b2e467b045edf662ba5667f4588a9f44d.png)

Any possibility of achieving this results using a regular pie-chart?  
Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [November 26, 2021, 10:29am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271/2 "2021-11-26T10:29:48Z")

</div>

Hi there, you could achieve it using filters aggregation on lens or regular pie chart visualization, here's the example (filters where one uses `and` operator):

 ![Screenshot 2021-11-26 at 11.29.10](https://us1.discourse-cdn.com/elastic/original/3X/5/2/528f21df1b3b25d696a976c54fae18202f23fd43.jpeg)

---

<div class="post-metadata">

**Author:** ![thenotoriousciu](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@thenotoriousciu](https://discuss.elastic.co/u/thenotoriousciu)\
**Post date:** [November 26, 2021, 11:09am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271/3 "2021-11-26T11:09:42Z")

</div>

Hello, Marta.  
Thanks for your reply. Unfortunately, the data that you used is not structured is the same way as mine. In your example, you could have multiple instances of category.keyword in the same record (basically, multiple products of different types). For my example, imagine that I have just one occurence of category.keyword in my record.

To use your data in my example, let's assume a customer bought a product from "Men's accesories" and one product from "Men's clothing". In my example, this would produce 2 records, each one with its own category.keyword field (see below an example of what I am reffering to):

```auto
  {
        "_index" : "kibana_sample_data_ecommerce",
        "_type" : "_doc",
        "_id" : "2-dm8nsBcBtKmSN2zsMN",
        "_score" : 0.0,
        "_source" : {
          "currency" : "EUR",
          "customer_first_name" : "Sultan Al",
          "customer_full_name" : "Sultan Al Thompson",
	      "category" : "Men's Clothing",
          "customer_gender" : "MALE",
          "customer_id" : 19,
          "customer_last_name" : "Thompson",
          "customer_phone" : "",
          "day_of_week" : "Tuesday",
          "day_of_week_i" : 1,
          "email" : "sultan al@thompson-family.zzz",
        }
      },
     {
        "_index" : "kibana_sample_data_ecommerce",
        "_type" : "_doc",
        "_id" : "2-dm8nsBcBtKmSN2zsMN",
        "_score" : 0.0,
        "_source" : {
          "currency" : "EUR",
          "customer_first_name" : "Sultan Al",
          "customer_full_name" : "Sultan Al Thompson",
		  "category" : "Men's Accessories",
          "customer_gender" : "MALE",
          "customer_id" : 19,
          "customer_last_name" : "Thompson",
          "customer_phone" : "",
          "day_of_week" : "Tuesday",
          "day_of_week_i" : 1,
          "email" : "sultan al@thompson-family.zzz",
        }
      }

```

So, for my example, this client would have to be labeled as "Hybrid" in my pie-chart.

For my final pie-chart I have to count:

1. How many customers bought products from both "Men's acessories" and "Men's clothing" - these customers are Hybrid.
2. How many customers bought only from "Men's acessories"
3. How many customers bought only from "Men's clothing".

Thanks.  
Alex

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [November 26, 2021, 11:14am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271/4 "2021-11-26T11:14:30Z")

</div>

Understood. Yes, I am afraid in this case only Vega would suit your needs.

---

<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:** [December 24, 2021, 11:14am UTC](https://discuss.elastic.co/t/pie-chart-with-filtering/290271/5 "2021-12-24T11:14:57Z")

</div>

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