Conditional Count Column in Query

Conditional Count Column in Query

Post by cGNiaW5 » Sat, 04 Jul 2009 00:14:01


I have a table that shows:

REGION COND_A COND_B COND_C COND_D
NORTH N Y Y N
SOUTH N N N N
EAST Y Y N N
WEST N N N Y
CENTRAL N Y N N

I would like to run a query that will add a count column at the end, that
will count the number of "Y" conditions.

Is that possible? Or is this not the way to go about it?
 
 
 

Conditional Count Column in Query

Post by RHVhbmUgSG » Sat, 04 Jul 2009 00:34:01

I would normalize the table to something like:
Region Cond IsOK
North A N
North B Y
North C Y
North D N
South A N
South B N
-- etc ---
Then you could create a crosstab that uses Region as a Row Heading, IIf(IsOK
="Y",1,0) Sum as Row Heading, "COND_" & Cond as the Column Heading, and First
of IsOK as the Value.

--
Duane Hookom
Microsoft Access MVP