# Lens formulas count problem

**URL:** https://discuss.elastic.co/t/lens-formulas-count-problem/328050
**Category:** Kibana
**Tags:** lens
**Created:** [March 20, 2023, 7:55am UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050 "2023-03-20T07:55:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lize\_su](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lize_su/32/118653_2.png) [@lize\_su](https://discuss.elastic.co/u/lize_su)
#### Post date: [March 20, 2023, 7:55am UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050/1 "2023-03-20T07:55:01Z")

</div>

Hi all,  
I'm pretty new to kibana and trying to use below code to generate dashboard warning count in the last 1 hour:  
//count(kql='isAlarmTriggered : true')-count(kql='isAlarmTriggered : true',shift='1h')  
But sometimes the result becomes negative. Something must be wrong and I'm wondering why that's the case. Any explanation would be nice.

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [March 20, 2023, 9:48am UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050/2 "2023-03-20T09:48:24Z")

</div>

Hi @lize_su

welcome to the Kibana community.  
Is it possible that there's no document with the `isAlarmTriggered` set to `true` in the current timeframe, but there are for the past hour?  
If you open the Inspector panel with the raw ES response, can you see the data?

---

<div class="post-metadata">

### Author: ![lize\_su](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lize_su/32/118653_2.png) [@lize\_su](https://discuss.elastic.co/u/lize_su)
#### Post date: [March 20, 2023, 11:26am UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050/3 "2023-03-20T11:26:57Z")

</div>

Hi Marco,  
Thanks for the suggestion. I just went through the online documentation([Create visualizations with Lens | Kibana Guide [8.6] | Elastic](https://www.elastic.co/guide/en/kibana/current/lens.html#lens-formulas)) and found this:

```auto
You are unable to combine different time shifts, such as count(shift="1w") - count() and count(shift="1w") - count(shift="1m")

```

I guess maybe there's reason. And I found that using predefined count() can also perform the same task. Not going to investigate further, but thanks for your fast reply.

---

<div class="post-metadata">

### Author: ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)
#### Post date: [March 20, 2023, 12:06pm UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050/4 "2023-03-20T12:06:48Z")

</div>

That applies only when using the `Top Values` and no result is actually displayed in such case, rather suggested a workaround with a Filter operation in place of a Top Values.  
I do not think that is related to your issue.

---

<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: [April 17, 2023, 12:07pm UTC](https://discuss.elastic.co/t/lens-formulas-count-problem/328050/5 "2023-04-17T12:07:15Z")

</div>

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