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.

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

Now that we have the parameter we can click Done editing for that part and add new one by clicking on 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'

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:

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:

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

I hope this little tip was useful for you!