SOLVED
Home

useing let to create variable not working

DubG83
New Contributor

HI,

 

I'm new to Azure Log Analytics, so sorry or such a basic question.

 

From looking at this documentation https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/advanced-query-writing

 

I should be able to create a variable using let

 

for example

let CPUThreshold = 5;
pref| where TimeGenerated > now(-30m)
and ObjectName == "Processor"
and CounterName == "% Processor Time"
and InstanceName == "_Total"
and CounterValue > CPUThreshold
| project Computer, ObjectName
, CounterName, CounterValue
, TimeGenerated;

 

I get this

'where' operator: Failed to resolve column or scalar expression named 'CPUThreshold'

 

I'm not sure what I'm doing wrong.

 

2 Replies
Solution
let CPUThreshold = 5;
Perf
| where TimeGenerated > now(-30m)  
    and ObjectName == "Processor"  
    and CounterName == "% Processor Time"  
    and InstanceName == "_Total"  
    and CounterValue > CPUThreshold
| project Computer, ObjectName  , CounterName, CounterValue  , TimeGenerated

I removed the final ";" and also you had spelled "Perf" wrongly.  This now works 

Thanks,

taking away the ; did it.