# Conditional filter with exists operator

**URL:** <https://community.influxdata.com/t/conditional-filter-with-exists-operator/12534>\
**Category:** Fluxlang\
**Created:** [January 7, 2020, 4:36pm UTC](https://community.influxdata.com/t/conditional-filter-with-exists-operator/12534 "2020-01-07T16:36:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alespour](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alespour/32/5907_2.png) [@alespour](https://community.influxdata.com/u/alespour)\
**Post date:** [January 7, 2020, 4:36pm UTC](https://community.influxdata.com/t/conditional-filter-with-exists-operator/12534/1 "2020-01-07T16:36:43Z")

</div>

I am trying to write a custom function which would work on a schema that is not fixed (it may follow some tag naming convention for example). I wonder if it is possible because when I try a simple predicate in filter() such as

```auto
data
  |> filter(fn: (r) => 
	if precision == 4 and exists r._g4 then contains(value: r._g4, set: values)
	else if precision == 8 and exists r._g8 then contains(value: r._g8, set: values)
	else false
  )

```

with ‘exists’ operator, I still get error whenever a referenced property (tag \_g8 in this example) is not present in input table, despite the ‘if exists’ condition should resolve to false for missing property, I assume…

```auto
Result: _result
Error: cannot add type constraint @ 4:17-7:12: type error 0:0-0:0: missing object properties (_g8)

```

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [January 7, 2020, 5:22pm UTC](https://community.influxdata.com/t/conditional-filter-with-exists-operator/12534/2 "2020-01-07T17:22:37Z")

</div>

@alespour I may be wrong, but I think the issue lies with the type inference currently implemented in Flux. We are currently in the process of completely overhauling the type inference system by replacing the type inference algorithm. I don’t know exactly when all of the new functionality will land, but it’s getting close.
