percentilew
This page explains how to use the percentilew aggregation function in APL.
percentilew estimates a percentile when each row represents multiple observations. The weight gives the number of observations the row represents.
Usage
Syntax
Parameters
expr: The expression to calculate the percentile on. Accepts numeric (int,long,real),timespan, ordatetimevalues.weight: An integer expression representing the frequency weight for each record. Records with a weight less than or equal to0are skipped. Records with anullweight are counted once (weight1).percentile: A numeric constant between0and100specifying the target percentile.GroupingColumn(optional): A column to group the results by. If omitted,percentilewcalculates the weighted percentile across all records.
Returns
Returns the estimated value of expr at the requested weighted percentile. By default, the output column is named percentilew_<expr>_<percentile>.
Use case examples
Weighted median (P50) latency
This example estimates the 50th percentile (median) latency across pre-aggregated request buckets where each row records a latency value and the integer number of requests at that latency.
Query
Output
| percentilew_latency_50 |
|---|
| 20 |
Across the 18 weighted observations (eight 10s, six 20s, three 30s, and one 40), the 50th percentile is 20.
Multiple weighted percentiles by group
Calculate multiple weighted percentiles in the same summarize operator and group by another field.
Query
Output
| service | p50 | p75 |
|---|---|---|
| api | 20 | 20 |
List of related aggregations
- percentile: Calculates an estimated unweighted percentile of a column.
- percentileif: Calculates an estimated percentile for records that satisfy a predicate.
- avgw: Calculates the weighted average of an expression using an integer frequency weight.
- sumw: Calculates the weighted sum of an expression using an integer frequency weight.
- countw: Calculates the weighted count of records using an integer frequency weight.