# How to set an AND logic in the Filter Transform of Vega?

**URL:** <https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [February 1, 2021, 3:36pm UTC](https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854 "2021-02-01T15:36:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m-amano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m-amano/32/62977_2.png) [@m-amano](https://discuss.elastic.co/u/m-amano)\
**Post date:** [February 1, 2021, 3:36pm UTC](https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854/1 "2021-02-01T15:36:28Z")

</div>

I am using Elasticsearch v.7.10.2 and Vega version is v.4.3.0.

I want to filter the dataset using AND logic and any of those codes below did not work.  
They filter out the data if y equals to 0 no matter what y1 has.

```auto
1. {"type": "filter", "expr":"datum.y0 !== 0 & datum.y1 !== 0"}
2. {"type": "filter", "expr":"datum.y0 !== 0 && datum.y1 !== 0"}
3. {"type": "filter", "expr":"datum.y0 != 0 & datum.y1 != 0"}
4. {"type": "filter", "expr":"datum.y0 != 0 && datum.y1 != 0"}

```

I wonder why the code below works as I expected though. When I use the formula type, the value of `delete` would be `true`, only if y0 and also y1 is equal to 0.

```auto
{"type": "formula", "expr": "datum.y0 == 0 && datum.y1 == 0 ? true : false", "as":"delete"},

```

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [February 1, 2021, 5:38pm UTC](https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854/2 "2021-02-01T17:38:48Z")

</div>

Boolean and is `&&` in Javascript, so filter 2 and 4 should work. Are you sure your data is numeric though? Since `==` in JS is a loose equality, and `"0" == 0` but `"0" !== 0`

& is a bitwise operator.

---

<div class="post-metadata">

**Author:** ![m-amano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/m-amano/32/62977_2.png) [@m-amano](https://discuss.elastic.co/u/m-amano)\
**Post date:** [February 2, 2021, 1:07am UTC](https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854/3 "2021-02-02T01:07:29Z")

</div>

@wylie  
Hi, thank you for your reply.

> [@wylie](#):
>
> Are you sure your data is numeric though?

They are probably numeric, as you see the result below is `true`.

```auto
{"type": "formula", "expr":"isNumber(datum.y1) == true ? true : false","as":"numeric_y1"},
{"type": "formula", "expr":"isNumber(datum.y0) == true ? true : false","as":"numeric_y0"},

```

Also y0 and y1 is the default output fields of Stack Transform which I hope computes numeric items.

---

<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:** [March 2, 2021, 1:07am UTC](https://discuss.elastic.co/t/how-to-set-an-and-logic-in-the-filter-transform-of-vega/262854/4 "2021-03-02T01:07:42Z")

</div>

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