# How to apply filters to some fields in Lens

**URL:** https://discuss.elastic.co/t/how-to-apply-filters-to-some-fields-in-lens/370344
**Category:** Kibana
**Created:** [November 11, 2024, 6:58pm UTC](https://discuss.elastic.co/t/how-to-apply-filters-to-some-fields-in-lens/370344 "2024-11-11T18:58:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![syunusic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syunusic/32/4131_2.png) [@syunusic](https://discuss.elastic.co/u/syunusic)
#### Post date: [November 11, 2024, 6:58pm UTC](https://discuss.elastic.co/t/how-to-apply-filters-to-some-fields-in-lens/370344/1 "2024-11-11T18:58:55Z")

</div>

If I have a Legacy Metric with this formula:

```auto
sum(data.bills)/(sum(data.sales)

```

And I want to add a filter like this:

```auto
{ "match_phrase": { "data.style": "Lease" } }

```

But the documents that have the field `data.sales` never have the field `data.style`, so, when I apply the filter, shows no result.

Is there any way to "tell" Lens to apply that filter to the numerator (`sum(data.bills)`) and not to the denominator?

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [November 12, 2024, 7:18pm UTC](https://discuss.elastic.co/t/how-to-apply-filters-to-some-fields-in-lens/370344/2 "2024-11-12T19:18:19Z")

</div>

I wonder if you can add a runtime field for "data.style" in to documents and solve this problem?

> **[Runtime fields | Elasticsearch Guide \[8.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html)**

Thanks,  
Bhavya

---

<div class="post-metadata">

### Author: ![syunusic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syunusic/32/4131_2.png) [@syunusic](https://discuss.elastic.co/u/syunusic)
#### Post date: [December 4, 2024, 4:33pm UTC](https://discuss.elastic.co/t/how-to-apply-filters-to-some-fields-in-lens/370344/3 "2024-12-04T16:33:25Z")

</div>

At the end I did it with KQL filter in the actual formula.. something like this:

````auto
sum(data.bills,kql='data.style: "Lease"')/(sum(data.sales)```
And works perfectly.
````
