Count If in Access 2016?

britsgal

Board Regular
Joined
Apr 8, 2014
Messages
75
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

I know I can perform a "countif" in Excel but just wondering how I can do that in Access? I really don't want to use code just simple formula would work if that's possible. Here's what I want to do, I have a table containing location, item and on hand. I would like to count the # of zeroes or qty's less than zero by location. The table looks something like this. So in this case location "A" would have 3, Location "B" would have 1, and location "C" would have 3. Any help is appreciated.
[TABLE="width: 199"]
<tbody>[TR]
[TD]LOCATION[/TD]
[TD]ITEM[/TD]
[TD]On Hand[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]1[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]2[/TD]
[TD]-3[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]4[/TD]
[TD]-1[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]5[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]6[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]6[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]4[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]3[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]2[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]1[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]4[/TD]
[TD]9[/TD]
[/TR]
</tbody><colgroup><col><col span="2"></colgroup>[/TABLE]
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I would do this with two queries.

Query1
Code:
SELECT Sheet1.LOCATION, IIf([On Hand]<1,1,0) AS Cnt
FROM Sheet1;

Query2
Code:
SELECT Query1.LOCATION, Sum(Query1.Cnt) AS SumOfCnt
FROM Query1
GROUP BY Query1.LOCATION;
 
Upvote 0
Its actually pretty easy to do it one query also (you can aggregate on a calculated field), i.e.
Code:
SELECT LOCATION, Sum(IIf([On Hand]<1,1,0)) AS Cnt
FROM Sheet1
GROUP BY LOCATION;
 
Upvote 0
Wouldn't
Rich (BB code):
select Location, count(*) from Sheet1
where [on hand] < 0
group by Location

Be simpler?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top