# How can I filter a Vega data table to unique values of a field?

**URL:** <https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [October 14, 2021, 4:46pm UTC](https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761 "2021-10-14T16:46:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 14, 2021, 4:46pm UTC](https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761/1 "2021-10-14T16:46:49Z")

</div>

Hello All,

I have data that I am querying, and I want to be able to filter to unique values of a field on the data in the table, can I do that? If so can someone explain to me how?

Thank you!

---

<div class="post-metadata">

**Author:** ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)\
**Post date:** [October 14, 2021, 9:41pm UTC](https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761/2 "2021-10-14T21:41:19Z")

</div>

Hi @nsimi, I can think of several ways to create a table with just the unique values of a certain field.

- Use [aggregate transform](https://vega.github.io/vega/docs/transforms/aggregate/) to group by the needed field -- this will create a table with each row representing each unique value (could be multiple fields too).
- Use [window transform](https://vega.github.io/vega/docs/transforms/window/) to either group rows (similar to aggregate), or to do a more fancy processing, i.e. sort by the value, and use the `lag` operation to get the previous (`-1`) value of the field. Afterwards use the [filter transform](https://vega.github.io/vega/docs/transforms/filter/) to compare current and previous values, and if they are the same, filter them out.

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 15, 2021, 4:26pm UTC](https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761/4 "2021-10-15T16:26:17Z")

</div>

@nyuriks Thank you!

At first I was having an issue where it wasn't working it was grouping everything as one group then I realized I had it pointed at the wrong data set

Thank you!

---

<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:** [November 12, 2021, 4:26pm UTC](https://discuss.elastic.co/t/how-can-i-filter-a-vega-data-table-to-unique-values-of-a-field/286761/5 "2021-11-12T16:26:33Z")

</div>

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