COUNT_IF() GROUP BY ...

All functions > GROUP BY > COUNT_IF() GROUP BY ...

Returns the number of values in the group that are true.

Syntax

Diagram(
  Sequence(
    Terminal("COUNT_IF"),
    Terminal("("),
    NonTerminal("expr"),
    Terminal(")"),
    Choice(0, Skip(),
      Sequence(
        Terminal("FILTER"),
        Terminal("("),
        Terminal("WHERE"),
        NonTerminal("condition"),
        Terminal(")")
      )
    ),
    Choice(0, Skip(),
      Sequence(
        Terminal("GROUP BY"),
        OneOrMore(NonTerminal("feature"), Terminal(","))
      )
    )
  )
)
ParameterTypeRequiredDescription
exprBOOLEANYesThe boolean condition to evaluate
conditionBOOLEANNoThe condition to filter the values before aggregation
featureFEATURENoThe features to group by (many features are supported)

Notes

  • Counts how many values evaluate to TRUE
  • Equivalent to COUNT(CASE WHEN expr THEN 1 END)
  • NULL and FALSE values are not counted
  • Returns 0 if no values are TRUE
  • Can be used with WHERE clause to filter before counting
  • Can be used with GROUP BY clause for grouped counts

Examples

FeatureQL
SELECT
    f1 := ZIP(ARRAY[1,2,3,4,5] AS value).TRANSFORM(SELECT COUNT_IF(value % 2 = 0)).UNWRAP_ONE()  -- Count of even values
;
Result
f1 BIGINT
2

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19