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

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.

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.

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

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.

@wylie
Hi, thank you for your reply.

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

{"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.

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