4

I have a dashboard populated with a number of Kusto KQL Queries.

Sometimes, my query below returns zero results (for instance if by miracle, there are no failures in the last 24 hours).

//my dashboard query 
let failureResults = exceptions | where blahblahblah;
failureResults;

When there are no items that match the filters, my dashboard is filled with

'The query returned no Results'.

How could I go about checking if this variable is null and then doing a different op? For instance, if it's null, then I would just issue a print "No Failures for today, awesome!"; instead.

I have tried iff() statements and isempty(failures| distinct Outcome) and the like, but to no avail. For example, here is another one which didn't work:

failures | project column_ifexists(tostring(Outcome),"No failures where reported!")
FoxDeploy
  • 12,569
  • 2
  • 33
  • 48

2 Answers2

3

Well... Kind of...

let p_threshold = ... ;// set value
let failureResults = datatable(exception_id:int,exception_val:int,exception_text:string)[1,100,"Hello" ,2,200,"World"];
failureResults
| where exception_val > p_threshold
| as t1
| union kind=outer (print msg = 'No Failures for today, awesome!' | where toscalar(t1 | take 1 | count) == 0)
| project-reorder msg

let p_threshold = 0;

msg exception_id exception_val exception_text
1 100 Hello
2 200 World

let p_threshold = 300;

msg exception_id exception_val exception_text
No Failures for today, awesome!

Fiddle

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88
2

Just thought on an improved solution based on pack_all() and the bag_unpack plugin

let p_threshold = ... ;// set value
let failureResults = datatable(exception_id:int,exception_val:int,exception_text:string)[1,100,"Hello" ,2,200,"World"];
failureResults
| where exception_val > p_threshold
| as t1
| project result = pack_all()
| union kind=outer (print msg = 'No Failures for today, awesome!' | where toscalar(t1 | take 1 | count) == 0 | project result = pack_all())
| evaluate bag_unpack(result)

let p_threshold = 0;

exception_id exception_text exception_val
1 Hello 100
2 World 200

let p_threshold = 300;

msg
No Failures for today, awesome!

Fiddle

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88