MS ACCESS 2016, Count IIF issue

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
175
Hi All,

I have a table with two columns like the below and I want to write a query that will count the YES values grouping by the A column. Any suggestions?
I tried Count(IIf()) and DCOUNT functions but none of them worked...


1
YES
2 YES
3 YES
3
4 YES
5 NO
5
YES
5 YES

<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>
</tbody>



11
21
31
41
52

<colgroup><col style="width:48pt" width="64" span="2"> </colgroup><tbody>
</tbody>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
repairing the other query:

Code:
SELECT 
    [2P_TABLE].[ONE], 
    Sum(IIf([2P_TABLE].[TWO]="-1",1,0)) AS ycount
FROM 
    [2P_TABLE]
GROUP BY 
    [2P_TABLE].[ONE];

Reporting only groups with at least one yes answer:
Code:
SELECT 
    [2P_TABLE].[ONE], 
    Sum(IIf([2P_TABLE].[TWO] = -1, 1, 0)) AS ycount
FROM 
    [2P_TABLE]
WHERE
    [2P_TABLE] = -1
GROUP BY 
    [2P_TABLE].[ONE];

I think that would work - untested.

Or:
Code:
SELECT 
	[2P_TABLE].[ONE], 
	SUM(-[2P_TABLE].[TWO]) AS ycount
FROM [2P_TABLE]
GROUP BY [2P_TABLE].[ONE]
HAVING SUM(-[2P_TABLE].[TWO]) > 0;
 
Last edited:
Upvote 0
Good.
And I made one mistake:
Code:
Sum(IIf([2P_TABLE].[TWO] = "-1", 1, 0)) AS ycount
should have been:
Code:
Sum(IIf([2P_TABLE].[TWO] = -1, 1, 0)) AS ycount
 
Upvote 0

Forum statistics

Threads
1,221,710
Messages
6,161,445
Members
451,706
Latest member
SMB1982

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