Share via

Display a message in KQL when no results or conditions match

$@chin 325 Reputation points
2024-04-05T16:30:37.9266667+00:00

How can I display a message if there are no results for the condition below, allowing it to be pinned to a dashboard ?

Perf
| where (CounterName == "% Processor Time")
| where _SubscriptionId contains "**************"
| summarize CPU_Used=avg(CounterValue) by bin(TimeGenerated, 24h), Computer =  tostring(split(Computer, ".")[0])
| where CPU_Used > 85 and CPU_Used < 95
| render timechart

Trying below query encounter with error User's image

Azure Monitor
Azure Monitor

An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.

{count} votes

2 answers

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,566 Reputation points Moderator
    2024-04-22T07:40:08.5666667+00:00

    @$@chin thank you for the question and providing additional details.

    The iff() function cannot be used in this case as the "then" and "else" parameters requires a scalar datatype (or inbuilt data type like numbers, string etc.), The provided type is not evaluated which means "render timechart" will not work.

    For your requirement, you could simply use the query. If there are no data available to plot anything, by default, the pinned visual on Azure dashboard will show "No data for the given query" (which cannot be customized at the moment):

    User's image

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    0 comments No comments

  2. Clive Watson 7,951 Reputation points MVP Volunteer Moderator
    2024-04-08T09:29:58.2266667+00:00

    Hello, the error you have is a syntax one, iif() would be something like this eample, using extend.
    However this wont solve your main issue, as the line "| where CPU_Used > 85 and CPU_Used < 95" means the next line isnt evaluated, as only the results between 85 --> 95 are shown. Remember that KQL is filtering the input, and you've filtered the answer out, just leaving null at this stage. By default you get "No results found from the last 24 hours" message. Azure Workbooks allow you to supply an alternative message, but I dont know if Azure Dashboards do that?

    | extend noresults_ = iif(isempty(CPU_Used),"y","n")
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.