# Unique count two fields combined

**URL:** <https://discuss.elastic.co/t/unique-count-two-fields-combined/268987>\
**Category:** Kibana\
**Created:** [April 1, 2021, 6:51am UTC](https://discuss.elastic.co/t/unique-count-two-fields-combined/268987 "2021-04-01T06:51:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kasun](https://avatars.discourse-cdn.com/v4/letter/k/4491bb/32.png) [@kasun](https://discuss.elastic.co/u/kasun)\
**Post date:** [April 1, 2021, 6:51am UTC](https://discuss.elastic.co/t/unique-count-two-fields-combined/268987/1 "2021-04-01T06:51:59Z")

</div>

Hi all,

For a pie chart, I am using unique count aggregation as the metric. However, I need to get the unique count when two fields combined. Is this possible using the advanced option in kibana visualizations?

As an example, If I have two fields as userId and companyName, I need the unique count of userId + companyName as the metric.

Thanks.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [April 1, 2021, 6:59am UTC](https://discuss.elastic.co/t/unique-count-two-fields-combined/268987/2 "2021-04-01T06:59:49Z")

</div>

You can do this by creating a scripted field ([Scripted fields | Kibana Guide [7.12] | Elastic](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html)) concatenating the values of the two original fields, then doing a unique count on that.

---

<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 29, 2021, 7:00am UTC](https://discuss.elastic.co/t/unique-count-two-fields-combined/268987/3 "2021-04-29T07:00:23Z")

</div>

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