Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CountIf formula within MS Access report

Something terrible as happened with my poor attempt at adding a CountIf forumula to my access report.

I am trying to add a formula within my report header to count the number of entries in my Service column that contain a certain word. The problem is I am an absolute amateur when it comes to SQL code.

=CountIf([Service]="Housing")

Is the code I was hoping would work but I don't seem to be getting anywhere.

like image 865
Kris Avatar asked Jul 02 '12 14:07

Kris


2 Answers

There is no Countif function in Access. However, you can use Sum and IIf (ie, Immediate If) to accomplish the same thing. Try:

=Sum(IIf([Service] Like "*Housing*", 1, 0))

The above assumes you want the Service column to contain the word "Housing". This assumes you were being precise in the wording of your question. If you really meant that you want to count the number of records where the Service column equals "Housing" exactly, you would use this instead:

=Sum(IIf([Service] = "Housing", 1, 0))
like image 130
mwolfe02 Avatar answered Sep 24 '22 06:09

mwolfe02


This also works:

=Count(IIf([Service]="Housing",1))
like image 20
David Newton Simiyu Avatar answered Sep 20 '22 06:09

David Newton Simiyu