Count X in Google Sheets: Formula & Examples

How-to basics · Updated November 23, 2026

To count how many times a specific value or text (like “x”) appears in a Google Sheets range, use the COUNTIF function: =COUNTIF(range, "x"). For example, =COUNTIF(A2:A100, "x") returns the number of cells in A2:A100 that contain exactly “x”. If you need to count cells that contain “x” as part of a longer text, use a wildcard: =COUNTIF(A2:A100, "*x*").

Why COUNTIF Is the Go-To Function

Google Sheets offers several counting functions, but COUNTIF is the most direct for counting a specific value. It combines the counting power of COUNT with a condition. The syntax is simple: COUNTIF(range, criterion). The criterion can be a number, text, a comparison operator (like “>10”), or a wildcard pattern. For counting “x” specifically, you use either an exact match or a partial match, depending on your data.

Unlike COUNT which only counts numeric cells, COUNTIF handles text, numbers, and dates. It is case-insensitive by default, so it counts both “X” and “x”. If you need case-sensitive counting, you would need to use a more advanced formula with ARRAYFORMULA and EXACT.

Exact vs. Partial Match: The Wildcard Trick

The main decision when counting “x” is whether you want to count cells that contain exactly “x” or cells that contain “x” anywhere. Here’s how to do both:

  • Exact match (cell equals “x”): =COUNTIF(A2:A100, "x") — counts only cells where the entire content is “x”.
  • Partial match (cell contains “x” as a substring): =COUNTIF(A2:A100, "*x*") — the asterisks are wildcards that match any sequence of characters, so this counts cells like “x-ray”, “max”, or “x”.
  • Starts with “x”: =COUNTIF(A2:A100, "x*") — counts cells beginning with “x”.
  • Ends with “x”: =COUNTIF(A2:A100, "*x") — counts cells ending with “x”.

Note that wildcards work only with text criteria, not with numeric criteria. If you are counting numbers, use comparison operators like =COUNTIF(A2:A100, ">5").

Counting Across Multiple Columns or Sheets

If your data spans multiple columns, you can use COUNTIF with a combined range in Google Sheets (unlike Excel, which requires separate functions). For example, to count “x” in both columns A and B, use:

=COUNTIF(A2:B100, "x")

This works because Google Sheets allows a 2D range in COUNTIF. For counting across different sheets, you can add multiple COUNTIF results:

=COUNTIF(Sheet1!A2:A100, "x") + COUNTIF(Sheet2!A2:A100, "x")

If you need to count across many sheets, consider using SUMPRODUCT with COUNTIF indirectly, but the simple addition is usually sufficient.

Counting with Multiple Criteria: COUNTIFS

When you need to count “x” only if another condition is met, use COUNTIFS. For instance, to count cells in column A that contain “x” and where column B equals “Yes”:

Assuming data in A2:A100 and B2:B100, use:

=COUNTIFS(A2:A100, "*x*", B2:B100, "Yes")

This function accepts multiple range-criterion pairs. Each range must have the same number of rows and columns. You can add as many pairs as needed.

Common Problems and Fixes

Here are frequent issues users encounter when counting “x” in Google Sheets:

  • Counting blank cells as “x”: If you accidentally use "*x*" and the cell is empty, it won’t count, but if you use "*" alone, it counts all non-empty cells. To avoid confusion, be explicit with your criteria.
  • Case sensitivity: COUNTIF is not case-sensitive. If you need to distinguish between “X” and “x”, use this formula: =ARRAYFORMULA(SUM(--EXACT(A2:A100, "x"))) — this counts only lowercase “x” (or uppercase if you change the criterion).
  • Counting cells with leading/trailing spaces: If a cell contains ” x ” (with spaces), COUNTIF with “x” won’t count it. Use =COUNTIF(A2:A100, "*x*") to catch it, or clean the data with TRIM first.
  • Formula not updating: If you change data and the count doesn’t update, check that your range is correct and that you haven’t accidentally set calculation to manual (File > Settings > Calculation).

Counting in a Row or a Column: Practical Examples

Let’s walk through a concrete example. Suppose you have a list of survey responses in column A (A2:A10) with values: “x”, “y”, “x”, “z”, “x”, “x”, “y”, “x”, “x”.

  1. To count how many responses are “x”: =COUNTIF(A2:A10, "x") returns 6.
  2. To count responses that contain “x” (like “x-ray”): =COUNTIF(A2:A10, "*x*") returns 6 (since all are exactly “x”, but if there were “x-ray”, it would count that too).
  3. To count responses that are NOT “x”: =COUNTIF(A2:A10, "<>") returns 4 (since there are 4 non-“x” cells).

For a row, say B1:Z1, use =COUNTIF(B1:Z1, "x").

Alternatives: SUMPRODUCT and QUERY

While COUNTIF is the simplest, there are other ways to count “x” that offer more flexibility:

  • SUMPRODUCT: =SUMPRODUCT(--(A2:A100="x")) counts exact matches. This is useful for case-sensitive counting when combined with EXACT: =SUMPRODUCT(--EXACT(A2:A100, "x")).
  • QUERY: =QUERY(A2:A100, "select count(A) where A = 'x' label count(A) ''") returns the count. This is helpful if you want to group by other columns later.
  • FILTER: =COUNTA(FILTER(A2:A100, A2:A100="x")) also works, but it’s longer and less efficient for large datasets.

For most users, COUNTIF is the best balance of simplicity and power.

Frequently Asked Questions

How do I count cells that contain “x” but not “y”?

Use COUNTIFS with two criteria: =COUNTIFS(A2:A100, "*x*", A2:A100, "<>*y*"). This counts cells that have “x” anywhere but do not have “y” anywhere. Note that this counts cells like “x” and “x-ray”, but not “xy” because that contains “y”.

Does COUNTIF count cells with “x” in formulas or numbers?

No, COUNTIF counts based on the displayed value, not the underlying formula. If a cell contains a formula that returns “x”, it will be counted. If a number is formatted as text and shows “x”, it will also be counted. But if a cell contains a number like 10, it won’t match “x” unless you use a wildcard that matches numbers as text, which is not recommended.

How do I count “x” in a column ignoring blank cells?

Blank cells are automatically ignored by COUNTIF because they don’t match “x” or “*x*”. So =COUNTIF(A:A, "x") will not count blanks. If you want to count non-blank cells that are not “x”, use =COUNTIF(A:A, "<>").

Can I count “x” in a filtered list?

Yes, COUNTIF works on the underlying data, not just visible cells. If you filter your data, the formula still counts all cells in the range, including hidden ones. To count only visible cells, use SUBTOTAL with function code 103 (COUNTA) combined with a condition, but that’s more complex. For most cases, COUNTIF is fine.

Why is my COUNTIF returning 0 when I see “x” in the cells?

This usually happens because the cells contain extra spaces, or the “x” is actually a different character (like a capital X or a special Unicode character). Try using =COUNTIF(A2:A100, "*x*") to catch spaces, or check if the cells have leading/trailing spaces with =LEN(A2). Also, ensure the range is correct and doesn’t include headers.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.