Conditional Count Column in Query

P

pcbins

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?
 
D

Duane Hookom

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top