# Function all in canvas and asset

**URL:** <https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [May 11, 2020, 11:15am UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990 "2020-05-11T11:15:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jcarlovich](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jcarlovich](https://discuss.elastic.co/u/Jcarlovich)\
**Post date:** [May 11, 2020, 11:15am UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/1 "2020-05-11T11:15:38Z")

</div>

Hi,

I want to create a condition and use asset for the next query:

query="SELECT count(\*) as y , ESTADO as e FROM "vdf-procesos-tareas" WHERE ESTACION = 'IMS' GROUP BY ESTADO"

result:

![image](https://us1.discourse-cdn.com/elastic/original/3X/8/8/8884ace3f6fe510389c0e560e647fe64802773f9.png)

now I want to create the following conditions for which you will return a corresponding asset to me. this is the query:

```
    filters
    | essql 
      query="SELECT count(*) as y, ESTADO as e FROM \"vdf-procesos-tareas\" WHERE ESTACION = 'Radius' GROUP BY ESTADO"

    |image mode="contain" dataurl={switch  
      case={case if={all {getCell "y" | compare "eq" to=2} {getCell "e" | compare eq to="WAITING"}} then= {asset asset-28b6df7f-49d1-4f82-ab86-4f4d15b613e8}}
      case={case if={all {getCell "y" | compare "gte" to =3} {getCell "e" | compare eq to="WAITING"}} then= {asset asset-e39d55b1-0e1b-4b13-a29e-691337a08670}}
      case={case if={all {getCell "y" | compare "gte" to =2} {getCell "e" | compare eq to="SUSPENDED"}} then= {asset asset-eb300919-21e1-438b-a66a-f2ebf485675d}}
      default= {asset asset-9691b2ce-eeda-4b3b-b89d-13a1a0680768}
           }
    | render 

```

this returns the default but should not

Thanks

---

<div class="post-metadata">

**Author:** ![corey.robertson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corey.robertson/32/54611_2.png) [@corey.robertson](https://discuss.elastic.co/u/corey.robertson)\
**Post date:** [May 11, 2020, 6:20pm UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/2 "2020-05-11T18:20:05Z")

</div>

Hi @Jcarlovich

When you are using `getCell`, unless otherwise specified, will get the cell from the first row.

So, your switch statement is (in pseudo code)

```auto
if y == 2 AND e == "WAITING" then Asset1
if y >= 3 AND e == "WAITING" then Asset2
if y >= 2 AND e == "SUSPENDED" then Asset3
default Asset4

```

So, you're always getting the row of `398 | COMPLETE` which does not match any of the options for the switch, so it falls into default.

Hope that helps you understand what's going on.

---

<div class="post-metadata">

**Author:** ![Jcarlovich](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jcarlovich](https://discuss.elastic.co/u/Jcarlovich)\
**Post date:** [May 11, 2020, 7:23pm UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/3 "2020-05-11T19:23:10Z")

</div>

Thank you very much for responding. @corey.robertson

If I noticed and solved it by adding to the query :

> query="SELECT count(\*) as y, ESTADO as e FROM "vdf-procesos-tareas" WHERE ESTACION = 'IMS' ESTADO != 'COMPLETE' GROUP BY ESTADO"

`

But of course, it only worked for me when the first row was in compliance with the clause. Thanks to your answer I have read the documentation better and understood. Now, by sorting the results alphabetically (they can only be Complete, Suspended or Waiting) you can assign get cell the row to make the comparison.

```
filters
| essql 
  query="SELECT count(*) as y, ESTADO as e FROM \"vdf-procesos-tareas\" WHERE ESTACION = 'IMS' ESTADO != 'COMPLETE' GROUP BY ESTADO"
|image mode="contain" dataurl={switch  
  
  case={case if={all {getCell c="y" r=1| compare "eq" to=2} {getCell c= "e" r = 1 | compare eq to="WAITING"}} then= {asset asset-28b6df7f-49d1-4f82-ab86-4f4d15b613e8}}
  case={case if={all {getCell c="y" r=1 | compare "gte" to =3} {getCell c= "e" r=1| compare eq to="WAITING"}} then= {asset asset-e39d55b1-0e1b-4b13-a29e-691337a08670}}
  case={case if={all {getCell c="y" r=2 | compare "gte" to =2} {getCell c="e" r=2 | compare eq to="SUSPENDED"}} then= {asset asset-eb300919-21e1-438b-a66a-f2ebf485675d}}
   default= {asset asset-9691b2ce-eeda-4b3b-b89d-13a1a0680768}
       }
| render 

```

But what do I do when only a value or two comes up? The order would not correspond... can get cell solve this case similar with one loop?

thanks

---

<div class="post-metadata">

**Author:** ![corey.robertson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corey.robertson/32/54611_2.png) [@corey.robertson](https://discuss.elastic.co/u/corey.robertson)\
**Post date:** [May 11, 2020, 7:33pm UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/4 "2020-05-11T19:33:57Z")

</div>

What is the end result that you are trying to achieve? If you are looking for an image per status, then you would need to break it up into separate elements for each potential status. So you would have one for "SUSPENDED" and one for "COMPLETE", etc.

---

<div class="post-metadata">

**Author:** ![Jcarlovich](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jcarlovich](https://discuss.elastic.co/u/Jcarlovich)\
**Post date:** [May 11, 2020, 8:14pm UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/5 "2020-05-11T20:14:39Z")

</div>

Yeah, I think I'll add another classula WHERE in the essql for status .

Thanks @corey.robertson

---

<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:** [June 8, 2020, 8:14pm UTC](https://discuss.elastic.co/t/function-all-in-canvas-and-asset/231990/6 "2020-06-08T20:14:40Z")

</div>

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