countw
This page explains how to use the countw aggregation function in APL.
countw counts the observations represented by each row. The weight gives the number of observations the row represents.
Usage
Syntax
APL
Parameters
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 also skipped.GroupingColumn(optional): A column to group the results by. If omitted,countwcalculates the weighted count across all records.
Returns
Returns a long integer equal to the sum of positive integer weights across the group. By default, the output column is named countw_<weight>.
Use case examples
Weighted request count
This example counts total requests across pre-aggregated latency buckets where each row carries an integer request count.
Query
APL
Output
| countw_requests |
|---|
| 18 |
This query sums the positive integer weights: 8 + 6 + 3 + 1 = 18.
Weighted count with grouping and skipped weights
Records with a weight of 0, a negative integer, or null are skipped.
Query
APL
Output
| service | total_samples |
|---|---|
| api | 10 |
| web | 4 |
List of related aggregations
- count: Counts the total number of records in a group.
- countif: Counts 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.
- percentilew: Calculates an estimated weighted percentile using an integer frequency weight.