Function all in canvas and asset

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

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

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)

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.

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

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.

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

Thanks @corey.robertson

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