Overview

pow

pow is useful whenever you need to apply a power function to a metric, such as squaring deviations for variance calculations, computing exponential growth factors, scaling values by a fractional power, or inverting a power transformation. It's more flexible than exp, exp2, or exp10 because you can specify any base.

Usage#

Syntax#

pow(base, exponent)

Parameters#

Name Type Required Description
base real Yes The base value.
exponent real Yes The exponent to raise the base to.

Returns#

base raised to the power exponent: base^exponent.

Example#

Use pow to square the deviation of each request's duration from a 200 ms baseline.

Query

['sample-http-logs']
| extend deviation = req_duration_ms - 200.0
| extend squared_deviation = pow(deviation, 2)
| project _time, id, req_duration_ms, squared_deviation
| order by squared_deviation desc

Run in Playground

Output

_time id req_duration_ms squared_deviation
2024-11-14 10:00:00 user-1 1200.0 1000000.0
2024-11-14 10:01:00 user-2 80.0 14400.0
2024-11-14 10:02:00 user-3 205.0 25.0
  • sqrt: Returns the square root of a value. This is equivalent to pow(x, 0.5) and is more readable for the square-root case.
  • exp: Returns e^x. Use it when the base is e rather than an arbitrary number.
  • exp2: Returns 2^x. Use it when the base is always 2.
  • exp10: Returns 10^x. Use it when the base is always 10.
  • log: Returns the natural logarithm. Use it to undo a pow transformation in log space.

Other query languages#

Splunk SPL users

In Splunk SPL, pow(base, exponent) works identically to APL's pow. You can also use the ^ operator for the same purpose.

Splunk example

| eval squared = pow(req_duration_ms, 2)

APL equivalent

['sample-http-logs']
| extend squared = pow(req_duration_ms, 2)
ANSI SQL users

In ANSI SQL, POWER(base, exponent) provides the same functionality as APL's pow.

SQL example

SELECT POWER(req_duration_ms, 2) AS squared FROM logs

APL equivalent

['sample-http-logs']
| extend squared = pow(req_duration_ms, 2)

Updated

Was this page helpful?