# Solved: Is there a 'CountIf' function for Access?



## DKTaber

Have an Access 2000 report in which I would like to get a count of each different value in a single-character text field. The file can have the values A, B, E, and M. So in the report footer, I want four fields that count the A's, the B's, the E's and the M's separately. In other words, the same thing CountIf does in Excel. I can't find such a function in Access. Is there such a function?


----------



## jimr381

No and Yes. No there is not a countif persay, but you can nest an Iif within a count function like this. 
=count(Iif([field]=value))

For Yours it would be:

=count(Iif([fieldname]="A"))

=count(Iif([fieldname]="B"))

Each of these will be placed in separate text boxes.


----------



## DKTaber

jimr381 said:


> No and Yes. No there is not a countif persay, but you can nest an Iif within a count function like this.
> =count(Iif([field]=value))
> 
> For Yours it would be:
> 
> =count(Iif([fieldname]="A"))
> 
> =count(Iif([fieldname]="B"))
> 
> Each of these will be placed in separate text boxes.


Thanks for the quick response. I'll try it a let you know if it worked.


----------



## jimr381

Not a problem make sure you replace fieldname with the actual field name you are counting data within.


----------



## DKTaber

jimr381 said:


> Not a problem make sure you replace fieldname with the actual field name you are counting data within.


I did that, and it doesn't work; get an error message "The expression you entered has a function containing the wrong number of arguments". ????


----------



## jimr381

Whoops let me try that again.



jimr381 said:


> No and Yes. No there is not a countif persay, but you can nest an Iif within a count function like this.
> =count(Iif([field]=value))
> 
> For Yours it would be:
> 
> =count(Iif([fieldname]="A",1))
> 
> =count(Iif([fieldname]="B",1))
> 
> Each of these will be placed in separate text boxes.


Just add the ,1 in there as well.


----------



## DKTaber

jimr381 said:


> Whoops let me try that again.
> Just add the ,1 in there as well.


Yep, that was it. I figured that out shortly after my last reply because the Iif statement didn't have a result. Works perfectly. Thanks much.


----------



## jimr381

Not a problem can you please mark the post as solved via the "Thread Tools" drop-down list at the top of the post?


----------



## DKTaber

jimr381 said:


> Not a problem can you please mark the post as solved via the "Thread Tools" drop-down list at the top of the post?


Just did.


----------

