Search code examples
kqlazure-data-explorer

Create a function to calculate power of tens with a loop and reuse them in another query


I need a KQL function which calculates the power of tens (or maybe N), where I can pass the base and the exponent and get back the result.

I´m new in KQL, so I don´t know how exactly define the function and how to implement some sort of for-loop. Can someone help me out?


Solution

  • You could create a powerN function and use the range operator to loop over it, like this:

    let powerN = (base: real, exponent: int) {
        exp(log(base) * exponent)
    };
    range x from 1 to 10 step 1
    | project powerN(10, x)
    

    See the Demo here.

    Result:

    enter image description here