# Dashboards based on a subquery

**URL:** https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153
**Category:** Kibana
**Created:** [September 26, 2022, 9:21am UTC](https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153 "2022-09-26T09:21:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![shinobu](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@shinobu](https://discuss.elastic.co/u/shinobu)
#### Post date: [September 26, 2022, 9:21am UTC](https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153/1 "2022-09-26T09:21:16Z")

</div>

Hello,

I would like to aggregate data into a pie chart based on the newest data for a specific type id.  
In other words something like

category | type\_id | @timestamp

* * *

category1 | abcd | 2022-08-26  
category1 | abcd | 2022-08-25  
category1 | efgh | 2022-08-26  
category2 | xyz | 2022-08-26

This should result in a py chart with 2 segments. One that counted 2 (category1 with type\_id abcd efgh) and a slice of 1 (category 2 with type\_id xyz).

Thank you.

---

<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: [September 26, 2022, 9:27am UTC](https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153/2 "2022-09-26T09:27:52Z")

</div>

Not sure if completely got your request so please let me know if that's not what you're looking for. How about using a Lens pie chart with two slice by defined? (one for category, the other for id?)

 ![Screenshot 2022-09-26 at 11.26.56](https://us1.discourse-cdn.com/elastic/original/3X/3/3/33b24eb4aa765010234438bf5980e36a0905faaa.jpeg)

---

<div class="post-metadata">

### Author: ![shinobu](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@shinobu](https://discuss.elastic.co/u/shinobu)
#### Post date: [September 26, 2022, 9:40am UTC](https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153/3 "2022-09-26T09:40:06Z")

</div>

Thank you for your fast reply, but this is not exactly what i was looking for.

What i meant was counting all categories, but only count the newest type\_id if there are multiple.

Which would lead to 2 category counts  
category1 comes 3 times, but i only want to count abcd once =\> count of 2  
category2 only has xyz which is already unique

---

<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: [October 24, 2022, 9:40am UTC](https://discuss.elastic.co/t/dashboards-based-on-a-subquery/315153/4 "2022-10-24T09:40:08Z")

</div>

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