Conditional Count Column in Query

  • Thread starter Thread starter pcbins
  • Start date Start date
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?
 
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.
 
Back
Top