sumw
This page explains how to use the sumw aggregation function in APL.
sumw calculates the sum when each row represents multiple observations. The weight gives the number of observations the row represents.
Usage
Syntax
APL
Parameters
expr: The summable expression to total. Accepts numeric (int,long,real) ortimespanvalues.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).GroupingColumn(optional): A column to group the results by. If omitted,sumwcalculates the weighted sum across all records.
Returns
Returns the weighted sum of expr across the group (expr * weight summed over all included records). By default, the output column is named sumw_<expr>.
Use case examples
Weighted sum of latency
This example computes the total latency across pre-aggregated request buckets where each row records a latency value and the integer number of requests at that latency.
Query
APL
Output
| sumw_latency |
|---|
| 330 |
This query computes 10*8 + 20*6 + 30*3 + 40*1 = 330.
Weighted sum with non-positive weights excluded
Records with a weight of 0 or a negative integer are skipped.
Query
APL
Output
| service | total_latency |
|---|---|
| api | 120 |
| web | 130 |
List of related aggregations
- sum: Calculates the unweighted sum of a numeric field across a group.
- sumif: Calculates the sum of an expression for records that satisfy a predicate.
- avgw: Calculates the weighted average of an expression using an integer frequency weight.
- countw: Calculates the weighted count of records using an integer frequency weight.
- percentilew: Calculates an estimated weighted percentile using an integer frequency weight.