Search code examples
azure-application-insightskqlazure-monitor

How to concatenate number and string for datetime analysis in Kusto (KQL)?


I'm trying to set some parameters in an Azure Workbook.

For some reason, I can't concatenate two values to create some dynamic date filters.

I've tried:

  • '{LogBuffer}' + '{LogBufferUnits}'
  • {LogBuffer} + '{LogBufferUnits}'
  • strcat('{LogBuffer}', '{LogBufferUnits}')

All of these fail with some form of:

enter image description here

This works, so I know that it can be done:

enter image description here


EDIT 1: You're right...

At first, this worked... enter image description here

Then per your comment, realized I didn't need totimespan(); simplified down to... enter image description here


Solution

  • The solution is actually simpler than you think:

    print {LogBuffer}{LogBufferUnits}
    
    print_0
    00:10:00

    Workbook parameters are nothing more than textual placeholders, replaced pre-execution, with the supplied values.

    This is what your code looked like after the parameters were set:

    print '10' + 'm' 
    

    Arithmetic expression cannot be carried-out between StringBuffer and StringBuffer

    print 10 + 'm' 
    

    Arithmetic expression cannot be carried-out between I64 and StringBuffer

    This following code is valid, however the result is a string

    print strcat('10', 'm')
    

    Therefore, the following code is invalid

    print now() - strcat('10', 'm')
    

    Arithmetic expression cannot be carried-out between DateTime and StringBuffer

    This would have worked:

    print now() - totimespan(strcat('10', 'm'))
    
    print_0
    2022-09-23T05:37:33.726665Z