# In Vega, Filter one data table by another data table's contents

**URL:** <https://discuss.elastic.co/t/in-vega-filter-one-data-table-by-another-data-tables-contents/286747>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [October 14, 2021, 3:08pm UTC](https://discuss.elastic.co/t/in-vega-filter-one-data-table-by-another-data-tables-contents/286747 "2021-10-14T15:08:20Z")\
**Posts on this page:** 3\
**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, 3:08pm UTC](https://discuss.elastic.co/t/in-vega-filter-one-data-table-by-another-data-tables-contents/286747/1 "2021-10-14T15:08:20Z")

</div>

Hello,

I am trying to determine how I could filter data tables based on another tables contents.

e.g. Lets assume I have two tables; Table A that has items 1,3,5, and 7 in it.  
and Table B that has items 1,2,3,4,5, and 7 in it.

How can I filter these two tables such that I get a list of items that are either not in both or only in both?

Thank you!

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 15, 2021, 12:16pm UTC](https://discuss.elastic.co/t/in-vega-filter-one-data-table-by-another-data-tables-contents/286747/2 "2021-10-15T12:16:11Z")

</div>

I believe [this is](https://vega.github.io/editor/#/url/vega/N4IgJAzgxgFgpgWwIYgFwhgF0wBwqgegIDc4BzJAOjIEtMYBXAI0poHsDp5kTykSArJQBWENgDsQAGhAATJJhSoA2qHFIEcNCABmNAE4RM0kMSQAbBnAhpVIcQwRM4+tAEYAvlLWPnr1ADMXj5OLmgCwfa+YagA7B4AupHqmtoQcFASsiZmlta2IX7uydH+AEwlof5B3lFVaAAslUWoEbUO9XGJMpj6SOIQOmz6CAUgmACeOFro5mxsANYMOCY6+myj6HqGxjILcBPaHUUyenDmsjYqdUUJMkhXyiDImLAgSbWT09pDIwzmKHuV2eClgcGyMjgAA8cP4QDQdAAKeSYRyUF6wKQAAgA5BJzBMALRMNj0HHYnHiUnE0kwHEAShAiWZQA) what you are looking for.

```auto
{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": [
    {
      "name": "first",
      "values": [
         {"number": 1},
         {"number": 3},
         {"number": 5},
         {"number": 7}
      ]
    },
    {
      "name": "second",
      "values": [
        {"number": 1},
        {"number": 2},
        {"number": 3},
        {"number": 4},
        {"number": 5},
        {"number": 7}
      ],
      "transform": [
        {
          "type": "lookup",
          "from": "first",
          "key": "number",
          "fields": ["number"],
          "as": ["match"]
        },
        {"type": "formula", "as": "matched", "expr": "if(datum.match, 'only-both', 'not-both')"}
      ]
    }
  ]
}

```

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

---

<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, 12:16pm UTC](https://discuss.elastic.co/t/in-vega-filter-one-data-table-by-another-data-tables-contents/286747/3 "2021-11-12T12:16:21Z")

</div>

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