Using Optional parameter if not configured in Azure Monitor workbooks with KQL query – Cloud Administrator in Azure World


Azure Monitor workbooks are great way to visualize Azure data for monitoring and analysis. Although there is a good documentation on how to built them I would say that examples for more advanced scenarios are lacking in there. Recently I was asked a question about such scenario: “How do I set KQL query in a way that the filter for optional parameter in Azure Monitor workbook is not applied if value is not provided for that parameter?”.

To illustrate how this is possible let’s start by creating brand new workbook.

New workbook

Next let’s add an optional (not required) parameter of type text.

Optional parameter

Now that we have the parameter we can click Done editing for that part and add new one by clicking on Add query:

Add query

For simplicity we just going to use static value for the Log Analytics workspace we will query and use simple query as:

AzureActivity
| where ActivityStatusValue =~ 'Success'
Static query

As you can see we get results but the condition is static value not such coming from the parameter. If we replace the static value from the value of the parameter and run the query we get error:

KQL error

The way we can overcome that error if the parameter value is not configured is by using KQL to have where clause based on if the parameter is provided or not:

AzureActivity
|  where isempty('{ActivityStatus}') or (ActivityStatusValue =~ '{ActivityStatus}')

After running the query we get results for all activity logs regarding of the ActivityStatusValue value and as you can see our parameter is not configured:

Results without parameter

As soon as I provide value for the parameter the filtering works:

Results with parameter

I hope this little tip was useful for you!


Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment