countIf(field, condition) counts the rows where the condition is true, and distinct_countIf counts
the different values. Both are aggregations: in a visual by region they return one count per region,
and you can divide them by a plain count to get a rate.
Copy and paste
Returned orders:
countIf({Order ID}, {Status} = 'Returned')
Customers with at least one returned order:
distinct_countIf({Customer}, {Status} = 'Returned')
Return rate (format as a percentage):
countIf({Order ID}, {Status} = 'Returned') / count({Order ID})
Several conditions:
countIf({Order ID}, {Status} = 'Shipped' AND {Segment} = 'Enterprise')
Orders inside a date range set by parameters:
countIf({Order ID}, {Order Date} >= ${StartDate} AND {Order Date} <= ${EndDate})
Example
On the seven orders of this section:
| Region | Orders | Returned | Customers with a return | Return rate |
|---|---|---|---|---|
| North | 4 | 1 | 1 | 25.0% |
| South | 3 | 1 | 1 | 33.3% |
| Total | 7 | 2 | 2 | 28.6% |
The rate is a ratio of two counts, so the total row is 2 / 7, not the average of 25% and 33.3%.
What gets counted
- The first argument must be a field. Literal values don’t work, so
countIf(1, ...)is not a way to count rows. Use a field that is never null, usually the key. - Nulls are not counted.
countIf({Ship Date}, ...)skips the open order, whose ship date is empty, even when the condition is true. That is a feature when you count “shipped orders” and a bug when you count “orders”. - The condition is checked on each row, before the aggregation.
A row condition is not a customer condition
distinct_countIf({Customer}, {Sales} >= 800) counts customers with at least one order of 800 or
more. In the example that is only Carla, with a single order of 900. Anna has three orders and 1,200 in
total, but none of them reaches 800 on its own.
“Customers who spent 800 or more in total” is a different question: the total per customer has to be computed before the condition. QuickSight does that with a level-aware calculation; see how to count customers whose total is above a threshold.
countIf or a calculated flag
countIf keeps the condition inside one measure. When several visuals use the same condition, a
row-level field such as ifelse({Status} = 'Returned', 'Returned', 'Kept') can be clearer: it works as
a dimension, a filter and a colour, and the counts come from a plain count.
Checked against the Amazon Quick Sight function reference (October 2026). The example results were recomputed in DuckDB.