# Canvas switch images with two SQL select queries

**URL:** <https://discuss.elastic.co/t/canvas-switch-images-with-two-sql-select-queries/274979>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [June 4, 2021, 12:18pm UTC](https://discuss.elastic.co/t/canvas-switch-images-with-two-sql-select-queries/274979 "2021-06-04T12:18:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martb/32/78185_2.png) [@martb](https://discuss.elastic.co/u/martb)\
**Post date:** [June 4, 2021, 12:18pm UTC](https://discuss.elastic.co/t/canvas-switch-images-with-two-sql-select-queries/274979/1 "2021-06-04T12:18:16Z")

</div>

HI,

I'm trying to switch the image from **green to amber when there are no records in the last hour** and change to **red when no records in the last 2hrs**. All within one indicator.

I've tried various ways to-do this but all have failed. I know the below isn't correct but I was simply trying to see if I could get two queries to work within one element, it does add the two values together but this isn't what I need.  
Is there some way to read the nCount1h and nCount2h within the case statement or is this completely the wrong approach?

Any help would be greatly appreciated

filters  
` | essql query="SELECT COUNT(*) AS nCount1h FROM \"alm-alerts-*\" WHERE TIMESTAMPDIFF('hh', \"@timestamp\"::datetime, now()::datetime) < 1"`  
| math  
`{string "nCount1h+" {filters | essql query="SELECT COUNT(*) AS nCount2h FROM \"alm-alerts-*\" WHERE TIMESTAMPDIFF('hh', \"@timestamp\"::datetime, now()::datetime) < 2" | math "nCount2h"}}`  
| image dataurl={switch  
case={case if={gt x} then={asset asset-green}}  
case={case if={gt x} then={asset asset-amber}}  
case={case if={eq 0} then={asset asset-red}}  
default="asset-2693a32e-cb78-4ea4-9853-d8978cf00fc6"  
}  
mode="contain"  
| render

---

<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:** [July 2, 2021, 12:18pm UTC](https://discuss.elastic.co/t/canvas-switch-images-with-two-sql-select-queries/274979/2 "2021-07-02T12:18:54Z")

</div>

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