This page explains how to use the stdevif aggregation function in APL.
The stdevif
aggregation function in APL computes the standard deviation of values in a group based on a specified condition. This is useful when you want to calculate variability in data, but only for rows that meet a particular condition. For example, you can use stdevif
to find the standard deviation of response times in an HTTP log, but only for requests that resulted in a 200 status code.
The stdevif
function is useful when you want to analyze the spread of data values filtered by specific criteria, such as analyzing request durations in successful transactions or monitoring trace durations of specific services in OpenTelemetry data.
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
Splunk SPL users
In Splunk SPL, the stdev
function is used to calculate the standard deviation, but you need to use an if
function or a where
clause to filter data. APL simplifies this by combining both operations in stdevif
.
ANSI SQL users
In ANSI SQL, the STDDEV
function is used to compute the standard deviation, but it requires the use of a CASE WHEN
expression to apply a conditional filter. APL integrates the condition directly into the stdevif
function.
The stdevif
function returns a floating-point number representing the standard deviation of the specified column for the rows that satisfy the condition.
In this example, you calculate the standard deviation of request durations (req_duration_ms
), but only for successful HTTP requests (status code 200).
Query
Output
geo.country | stdev_req_duration_ms |
---|---|
US | 120.45 |
Canada | 98.77 |
Germany | 134.92 |
This query calculates the standard deviation of request durations for HTTP 200 responses, grouped by country.
In this example, you calculate the standard deviation of request durations (req_duration_ms
), but only for successful HTTP requests (status code 200).
Query
Output
geo.country | stdev_req_duration_ms |
---|---|
US | 120.45 |
Canada | 98.77 |
Germany | 134.92 |
This query calculates the standard deviation of request durations for HTTP 200 responses, grouped by country.
In this example, you calculate the standard deviation of span durations, but only for traces from the frontend
service.
Query
Output
kind | stdev_duration |
---|---|
server | 45.78 |
client | 23.54 |
This query computes the standard deviation of span durations for the frontend
service, grouped by span type (kind
).
In this example, you calculate the standard deviation of request durations for security events from specific HTTP methods, filtered by POST
requests.
Query
Output
geo.city | stdev_req_duration_ms |
---|---|
New York | 150.12 |
Berlin | 130.33 |
This query calculates the standard deviation of request durations for POST
HTTP requests, grouped by the originating city.
stdevif
, but instead of calculating the standard deviation, avgif
computes the average of values that meet the condition.sumif
when you want to aggregate total values instead of analyzing data spread.This page explains how to use the stdevif aggregation function in APL.
The stdevif
aggregation function in APL computes the standard deviation of values in a group based on a specified condition. This is useful when you want to calculate variability in data, but only for rows that meet a particular condition. For example, you can use stdevif
to find the standard deviation of response times in an HTTP log, but only for requests that resulted in a 200 status code.
The stdevif
function is useful when you want to analyze the spread of data values filtered by specific criteria, such as analyzing request durations in successful transactions or monitoring trace durations of specific services in OpenTelemetry data.
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
Splunk SPL users
In Splunk SPL, the stdev
function is used to calculate the standard deviation, but you need to use an if
function or a where
clause to filter data. APL simplifies this by combining both operations in stdevif
.
ANSI SQL users
In ANSI SQL, the STDDEV
function is used to compute the standard deviation, but it requires the use of a CASE WHEN
expression to apply a conditional filter. APL integrates the condition directly into the stdevif
function.
The stdevif
function returns a floating-point number representing the standard deviation of the specified column for the rows that satisfy the condition.
In this example, you calculate the standard deviation of request durations (req_duration_ms
), but only for successful HTTP requests (status code 200).
Query
Output
geo.country | stdev_req_duration_ms |
---|---|
US | 120.45 |
Canada | 98.77 |
Germany | 134.92 |
This query calculates the standard deviation of request durations for HTTP 200 responses, grouped by country.
In this example, you calculate the standard deviation of request durations (req_duration_ms
), but only for successful HTTP requests (status code 200).
Query
Output
geo.country | stdev_req_duration_ms |
---|---|
US | 120.45 |
Canada | 98.77 |
Germany | 134.92 |
This query calculates the standard deviation of request durations for HTTP 200 responses, grouped by country.
In this example, you calculate the standard deviation of span durations, but only for traces from the frontend
service.
Query
Output
kind | stdev_duration |
---|---|
server | 45.78 |
client | 23.54 |
This query computes the standard deviation of span durations for the frontend
service, grouped by span type (kind
).
In this example, you calculate the standard deviation of request durations for security events from specific HTTP methods, filtered by POST
requests.
Query
Output
geo.city | stdev_req_duration_ms |
---|---|
New York | 150.12 |
Berlin | 130.33 |
This query calculates the standard deviation of request durations for POST
HTTP requests, grouped by the originating city.
stdevif
, but instead of calculating the standard deviation, avgif
computes the average of values that meet the condition.sumif
when you want to aggregate total values instead of analyzing data spread.