Error #504 as result for DCOUNT function

I hope the picture tells it all: I’ve prepared simple array and just want to count occurrences of number “2”, but I can’t figure out why I get error as a result.

Am I missing something?

Hi

What you are looking for is COUNTIF(A2:A6;A3).

See here how to use DCOUNT

Regards

As mentioned by @PYS, you are using the database function incorrectly, and should consult the relevant help page (also referenced in that answer) to see how it is expected to work.

Specifically:

  1. Any “database” range (the first argument in DCOUNT) is expected to have field names in its first row. So when you define the range A2:A6 as database, you have 4 records having a single field each, named “1”. This is likely not what you wanted, and probably you wanted to extent the range to be A1:A6, where A1 would be something like “my_values” (I will continue with this assumption below).
  2. The “search criteria” range must reference at least two rows, where first row is again for field names, and following rows are for required values or conditions. E.g., you could put “my_values” to B1, and 3 to B2, and then use B1:B2 as your search criteria to get what you want.

The formula then would be:

=DCOUNT(A1:A6;;B1:B2)

Note that in this case, you also may count how many occurrences of 1 are there, because I assumed that A2 is part of the data, not the field name. If your original database range were used, then I needed to put “1” to B1 (the formula would become =DCOUNT(A2:A6;;B1:B2)), and then the search for 1 put to B2 would result in 0.

Mike, thank you very much. I think the problem was in the “search criteria”, which should be entered as range, not a single cell.