Skip to main content

window_stdevp

Knowledge Checkpoint

Readings that will help you understand this documentation better:

Definition

A window aggregation function that returns the (population) standard deviation of rows in a range relative to the current row.

Syntax

window_stdevp(agg_expr)
window_stdevp(agg_expr, order: order_expr, ...)
window_stdevp(agg_expr, range, order: order_expr, ...)
window_stdevp(agg_expr, range, order: order_expr, ..., reset: partition_expr, ...)
window_stdevp(agg_expr, range, order: order_expr, ..., partition: partition_expr, ...)
Examples
window_stdevp(count(users.id))
window_stdevp(count(users.id), order: count(users.id) | desc())
window_stdevp(count(users.id), -2..2, order: users.created_at | month())
window_stdevp(count(users.id), order: users.created_at | month(), reset: users.gender)

// Axis-aware examples
window_stdevp(revenue, order: 'rows') // Running standard deviation across rows
window_stdevp(revenue, order: 'columns', partition: 'rows') // Running standard deviation within each row
window_stdevp(revenue, order: 'x_axis' | desc()) // Running standard deviation in reverse row order
window_stdevp(revenue, order: 'legend', partition: 'x_axis') // Running standard deviation within each column

Input

  • agg_expr (required): An aggregation expression that we want to find the (population) standard deviation of.

  • range (optional): A range of rows to include in the (population) standard deviation. Negative values indicate rows before the current row, and positive values indicate rows after the current row, while 0 indicates the current row. If the beginning or end of the range is not specified, the range will include all rows from the beginning or end of the table. By default, if the range is not specified:

    • If order is specified, the range is ..0 (from the first row to the current row).
    • If order is not specified, the range is .. (from the first row to the last row).
  • order (required, repeatable): A field that is used for ordering. The order defaults to ascending. The order can be set explicitly with asc() or desc().

    You can also use axis references:

    • 'rows' or 'x_axis': Order by row position in the visualization
    • 'columns' or 'legend': Order by column position in the visualization

    Axis references can be modified with asc() or desc(): order: 'rows' | desc()

    warning

    If the specified order does not uniquely identify rows, the result of the function can be non-deterministic. For example, if you use order: users.age, and there are multiple users with the same age in the same partition, the result can be unexpected.

  • partition or reset (repeatable, optional): A field that is used for partitioning the table. You can also use axis references like 'rows', 'columns', 'x_axis', or 'legend'. If partitions are not specified:

    • If order is specified, the table will be partitioned by all other grouping columns.
    • If order is not specified, the table will be considered as a single partition.

Output

The (population) standard deviation of the current row and the rows within the specified range.

Sample Usages

Please refer to the sample usages in window_stdev.


Let us know what you think about this document :)