'Consider the where condition based on the parameter value in KQL

I'm using Azure Log Analytics.

//Below is the Log Analytics Function (e.g Function Name is "TestFunction")
SynapseIntegrationPipelineRuns
| where Level == LevelValue
| where PipelineName == PipelineNameValue
| where Parameters.DataSetName != "" and Parameters.DataSetName == DataSetNameValue

Function call examples:
Case1: TestFunction('Error', 'PipelineName','DataSetName')
Case2: TestFunction('Error', 'PipelineName','')

This is a generic pipeline Query, this pipeline may contain parameter called "DataSetName" or may not as well.

If I'm passing empty value in DataSetName parameter - it should not consider the 3rd where condition and just compare 1st two conditions. Is this achievable?



Solution 1:[1]

This could be your function in which for each where-statement either the input parameter is empty or if it is given it shall equal the column value:

.create-or-alter function TestFunction(LevelValue:string, PipelineNameValue:string, DataSetNameValue:string) {
    SynapseIntegrationPipelineRuns
    | where isempty(LevelValue) or Level == LevelValue
    | where isempty(PipelineNameValue) or PipelineName == PipelineNameValue
    | where isempty(DataSetNameValue) or Parameters.DataSetName == DataSetNameValue
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jules