> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# CountIf

The **CountIf** function returns the number of rows in a table or group for which all given conditions are true.

The **CountIf** function is an aggregate function.

Aggregate functions evaluate one or more rows of data and return a single value.

In a table element, the aggregate is calculated for each grouping. For information on how to add a grouping with an aggregate calculation to a table, see [Group columns in a table](/docs/create-and-manage-tables#group-columns-in-a-table).

In a table with no groupings, the aggregate is calculated for each row. For information on how to calculate summary statistics across all rows in a table, see [Add summary statistics to a table](/docs/create-and-manage-tables#add-summary-statistics-to-a-table).

To learn more about using aggregate functions, see [Building complex formulas with grouped data](https://www.sigmacomputing.com/resources/training-videos/table-grouping-and-functions#complex-formulas).

## Syntax

`CountIf(condition 1, condition 2+...)`

Function arguments:

* **condition 1** (required) The condition to test. If the condition is True, then the row will be counted.

  You can use [operators](/docs/operators-overview) in conditions.
* **condition 2+** (optional) Additional conditions to test. If multiple conditions are given, they must all be True in order to be counted.

## Notes

* When using **CountIf** with multiple conditions, the function uses the logical operator `AND` by default to combine them. This means that all conditions must be true in order for the row to be counted. To use other [operators](/docs/operators-overview), such as `OR`, you must explicitly state them in a condition.
  * For example, `CountIf([Store State] = "Michigan" or [Store State] = "California")` counts the rows where the *Store State* column has a value of `Michigan` or `California`.
* When using **CountIf** on a column with the logical data type, you can optionally omit the comparison operator and value.
  * For example, `CountIf([Submitted] = True)` is equivalent to `CountIf([Submitted])`.

## Examples

```
CountIf([Age] > 65)
```

Counts the rows where the value in the *Age* column is greater than `65`.

```
CountIf([Age] > 65, [State] = ”Ohio”)
```

Counts the rows where the value in the *Age* column is greater than 65 and the *State* column has a value of `Ohio`.

```
CountIf([Submitted])
```

Counts the rows where the value for the *Submitted* column is `True`.

```
CountIf(IsNotNull([Order Number]))
```

Counts the rows where the *Order Number* column is not null. **IsNotNull** returns `True` for values that are not `Null`.

```
CountIf([Store State] = "Michigan" or [Store State] = "California")
```

Counts the rows where the *Store State* column has a value of `Michigan` or `California`.

## Related resources

* [Count](/docs/count)
* [CountDistinct](/docs/countdistinct)
* [CountDistinctIf](/docs/countdistinctif)