Hi,
I have a typical scenario where we need to get a percentage of number of OK devices. Something like
Scenario 1
- Query Defective Devices count
- Divide ( Defective Devices / total)
There are 2 ESSQL queries which get me the Defective device & Total
Here is my attempt where i am successfully able to get the percentage of Defective devices.
filters "live"
| essql
query="SELECT COUNT(DISTINCT b4) as scount FROM \"myindex\" WHERE QUERY(' b4:/AT[0-9]+/ AND value:1')"
| math
{string "scount/" {filters | essql query="SELECT COUNT(DISTINCT b4) as pcount FROM \"myindex\" WHERE QUERY('b4:/AT[0-9]+/')" | math "pcount"}}
| formatnumber "0%" format="0,0.[0]%"
| metric "Defective Devices"
metricFont={font family="'Tw Cen MT', Helvetica, Arial, sans-serif" size=72 align="center" color="red" weight="bold" underline=false italic=false}
labelFont={font family="'Dubai Light', Helvetica, Arial, sans-serif" size=30 align="center" color="#FFFFFF" weight="normal" underline=false italic=false} metricFormat="0,0.[000]%"
| render
Now I wish to use the same logic to get the % of OK Devices. Should be straight away subtracting (100 - result ) but for some reason it does not work.
Scenario 2
- Subtract (total - defective) = Ok Devices
- Divide ( OK devices/ total)
Here is my unsuccessful attempt which only gives me the count of OK Devices
filters "live"
| essql
query="SELECT COUNT(DISTINCT b4) as pcount FROM \"myindex\" WHERE QUERY('b4:/AT[0-9]+/')"
| math
{string "pcount -" {filters | essql query="SELECT COUNT(DISTINCT b4) as scount FROM \"myindex\" WHERE QUERY(' b4:/AT[0-9]+/ AND value:1')" | math {string "scount -" {filters | essql query="SELECT COUNT(DISTINCT b4) as dcount FROM \"myindex\" WHERE QUERY('b4:/AT[0-9]+/')" | math "count(dcount)"}}}}
| formatnumber "0%" format="0,0.[000]%"
| metric "Ok Devices"
metricFont={font family="'Tw Cen MT', Helvetica, Arial, sans-serif" size=72 align="center" color="#4fbf48" weight="bold" underline=false italic=false}
labelFont={font family="'Dubai Light', Helvetica, Arial, sans-serif" size=30 align="center" color="#FFFFFF" weight="normal" underline=false italic=false} metricFormat="0,0.[000]"
| render
Is there any way i can add another math string expression to achieve the final result that is OK Device percentage ?