0

I am looking for a query than can work in Access that gives me the total count of users who completed certain requirements. I know I can group by column, the "tricky" part is that I need to group in one column if the user completed any of the requirements from columns B,C or D. In other words, this is my data:

User    Company A   B   C   D   E
John    ABC     1               1
Bob     ABC     1   1   1       1
Reggie  ABC             1   1   1
Alex    BCA     1               
Mary    BCA     1   1       
Jane    CBA     1   1   1   1

And this is the end result I'm looking:

Company A   E   F(B or C or D)
ABC     2   3   2
BCA     2   0   1
CBA     1   0   1
HansUp
  • 95,961
  • 11
  • 77
  • 135
chupeman
  • 1,095
  • 3
  • 11
  • 23

2 Answers2

0

You can use NZ (COALESCE in SQL) to make null values 0 then you can do "normal" work -- like adding them in this example:

 SELECT SUM(NZ(B,0)+NZ(C,0)+NZ(D,0)) AS F

or looking at your logic

 SELECT SUM(IIF(NZ(B,0)+NZ(C,0)+NZ(D,0) > 0,1,0) ) AS F

(nb, CASE WHEN THEN END would be used instead if IIF in SQL)

Hogan
  • 69,564
  • 10
  • 76
  • 117
0

You would use group by:

select Company,
       nz(SUM(A), 0) as A, nz(SUM(E), 0) as E,
       (nz(SUM(B), 0) + nz(SUM(C), 0) + nz(SUM(D), 0) ) as F
from table
group by Company;

EDIT:

Hogan's point is good, and easily incorporated:

select Company,
       nz(SUM(A), 0) as A, nz(SUM(E), 0) as E,
       (nz(MAX(B), 0) + nz(MAX(C), 0) + nz(MAX(D), 0) ) as F
from table
group by Company;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • I think he just wants to count the existence of B, C, or D as 1 per row. Your code would give 4 instead of 2 in the first row. – Hogan Aug 07 '15 at 19:09