show Count of "empty" records

G

GillWeb

Hi
I'm compiling a simple database to analyse responses to a
questionnaire, most of which are multiple choice responses. I need to
be able to have queries which show not only how many people chose each
response but also to include any response where no-one selected that
option - in other words, an empty response. Currently, all I can get
up is the number for each response that has been chosen at least once.

Seems to me that a lot of people have asked very similar questions but
although I've been searching for over an hour I can't find any reply
that tell me how to do it.

Can somebody tell me the simplest way please?

(Is NULL doesn't work as there is no data at all in unselected
responses)
 
K

Keith Wilby

GillWeb said:
Hi
I'm compiling a simple database to analyse responses to a
questionnaire, most of which are multiple choice responses. I need to
be able to have queries which show not only how many people chose each
response but also to include any response where no-one selected that
option - in other words, an empty response. Currently, all I can get
up is the number for each response that has been chosen at least once.

Seems to me that a lot of people have asked very similar questions but
although I've been searching for over an hour I can't find any reply
that tell me how to do it.

Can somebody tell me the simplest way please?

(Is NULL doesn't work as there is no data at all in unselected
responses)

You need to post some details about how your tables are set up. Are you
saying that you have a table full of questions and some answer fields are
empty? IsNull ought to work in that scenario but you might have zero-length
strings in which case use the Nz function.

Keith.
www.keithwilby.com
 
G

GillWeb

You need to post some details about how your tables are set up. Are you
saying that you have a table full of questions and some answer fields are
empty? IsNull ought to work in that scenario but you might have zero-length
strings in which case use the Nz function.

Keith.www.keithwilby.com- Hide quoted text -

- Show quoted text -

My table with questions uses "pick from list" for values I've typed in
for the responses, which might be along the lines of "Strongly Agree",
"Agree", "Disagree" etc. So if a person "Agrees" then the other
responses are not chosen in that record, of course.

When I try to run the query (one to analyse each question) it only
show me how many have actually chosen a particular "pick form list"
but not the ones where no-one has chosen that response to the
question. But I need to show them all, eventually, in a chart format.
At present this would only show the positives and leave out any
response which has never been chosen.

Hope I've made myself clear....
 
K

Keith Wilby

KARL DEWEY said:
You still did not "post some details about how your tables are set up."

I *think* I understand but I *don't* think it's easily possible unless I'm
missing the point.

I think the OP wants to count how many questions there are where no one has
answered (for example) "disagree". That's easy enough to hard code but
counting against a moving target, that it to say, flagging a question that
has no responses of a certain category from a range of categories is going
to be tricky and I don't have an immediate solution.

This is usually where an MVP steps in and posts a really simple solution and
I slap my forehead ;-)

Keith.
 
J

John Spencer

Well, first there needs to be some way to identify which answers are
available for which question. That is normally done in a table that shows
the questionId and the available responses. Since the OP does not seem to
have that structure I see no easy answer.

If the OP does have that structure, she/he needs to post the information on
the table structure so someone can pose a possible solution.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
C

Chris2

GillWeb said:
Hi
I'm compiling a simple database to analyse responses to a
questionnaire, most of which are multiple choice responses. I need to
be able to have queries which show not only how many people chose each
response but also to include any response where no-one selected that
option - in other words, an empty response. Currently, all I can get
up is the number for each response that has been chosen at least once.

Seems to me that a lot of people have asked very similar questions but
although I've been searching for over an hour I can't find any reply
that tell me how to do it.

Can somebody tell me the simplest way please?

(Is NULL doesn't work as there is no data at all in unselected
responses)

GillWeb,

Aircode to follow:

SELECT COUNT(Nz(YT1.YourColumn, 1))
FROM YourTable AS YT1
WHERE YT1.YourColumn IS NULL


Sincerely,

Chris O.
 
G

GillWeb

You still did not "post some details about how your tables are set up."
--
KARL DEWEY
Build a little - Test a little








- Show quoted text -


I'll try again (you can tell I'm not a genius here!)

I have a single table where each field consists of the "pick-from-
list" options for one of the questions.
Each record consists of the choices made by any single responder to
all the questions.
From this table I have created a query for each field to group by the
response and count how many of each response there is.

So if 20 people chose to "agree", 15 to "disagree", no-one chose to
"strongly agree" and no-one chose to "strongly disagree", then when I
run the query all I see are the responses with 20 & 15 no mention of
the other two options. What I want is for it to actually show me that
there were 0 people who chose either of those options.

Hope that clarifies what I'm looking for - I just need a way to get it
show me ALL the values not just the positive numbers - to actually
return "0" for any option where no-one has made that choice and is
"empty"
 
G

GillWeb

GillWeb,

Aircode to follow:

SELECT COUNT(Nz(YT1.YourColumn, 1))
FROM YourTable AS YT1
WHERE YT1.YourColumn IS NULL

Sincerely,

Chris O.- Hide quoted text -

- Show quoted text -

Thanks Chris - that's wonderful - but right over my (female) head. I
don't know the term "Aircode" - I'm just a simple soul...
The help I need has to be at the "idiot's guide.." level I'm
afraid.....
 
G

Guest

From this table I have created a query for each field to group by the
response and count how many of each response there is.
Post your table structure - field names and datatype.
Post your query SQL. Open the query in design view, click on menu VIEW -
SQL View, highlight all, copy, and paste in a post.
 
C

Chris2

GillWeb said:
Thanks Chris - that's wonderful - but right over my (female) head. I
don't know the term "Aircode" - I'm just a simple soul...
The help I need has to be at the "idiot's guide.." level I'm
afraid.....

GillWeb,

Aircode is just like an airguitar, it sort of doesn't exist. In this
case, it was something that wasn't tested. It was something I threw
together and posted. "Aircode" is there to let you know that.

YourColumn and YourTable are generic terms I used that you are meant
to replace with your column's name and your table's name.

YT1 is a table alias.

Nz() is a function.

Nz(<expression>, <results if express IS NULL>)

<expression> = a column name
<results if expression IS NULL> = What the function returns if the
<expression> evaluates to NULL.

If the expression does not evaluate to NULL.

YourTable:
YourColumn:

1
2
NULL
3

Nz(YourColumn, 1) returns:

1
2
1 <NULL is replaced by 1>
3

Nz(YourColumn, 9999) returns:

1
2
9999 <NULL is replaced by 9999>
3

COUNT() counts the number of rows.

With Nz(YourColumn, 1) feeding the number 1 to the COUNT() function
surrounding it, and with the WHERE clause restricting the rows to ones
where YourColumn values are NULL, you are counting the NULL rows.
i.e. you are counting rows where no answer was put.

From your initial description, that is what I thought you wanted.


Create a copy of your database. Open the copy.

Create a new query.

Switch to SQL View (Menu Bar: View>SQL View)

Paste in my SQL code.


SELECT COUNT(Nz(YT1.YourColumn, 1))
FROM YourTable AS YT1
WHERE YT1.YourColumn IS NULL

Change YourTable to your table's name.

Change YT1 to an appropriate 1-3 letter/number abbreviation for your
table in all three locations.

Change YourColumn to the column name in your table where your answers
are stored (and where NULLs are stored for unanswered questions.)

That *should* work.


Sincerely,

Chris O.
 
C

Chris2

KARL DEWEY said:
KARL DEWEY Wrote:

response and count how many of each response there is.
Post your table structure - field names and datatype.
Post your query SQL. Open the query in design view, click on menu VIEW -
SQL View, highlight all, copy, and paste in a post.

Gillweb,

I echo Karl Dewey's comments.

Here's some more details that spell-out how to do this. It's quite
lengthy, but it has the information I believe you need.


The following contains information on how you can improve your chances
of getting your question answered:

-------------------------------

Formatting:

Please use a monospace font (Courier New, etc.) when writing out your
examples (all descriptions, charts, SQL, etc.).

-------------------------------

Process Description:

Please only include the shortest possible narrative of what is going
on with the query. (Include all that is necessary, and nothing more.)

When parts of your query make calculations, show the exact code or
nearest readable plain-text math formula you can create.

When you are done with this section, re-read it several times before
posting to assure yourself that you are accurately describing the
situation in a way you believe others will understand.

-------------------------------

Table Structures/Description:

Post a description of your table structures.

Open your table in Design View, view the column names and data types
in it, and then type out the column names and data types *that are
necessary* (do not include columns that are not absolutely necessary
for the query). Use the Index dialog box (you can get at it by
clicking on the "lightning bolt and stacked lines" icon on the
toolbar) to locate information on primary and foreign keys and other
indexes and type out that information, as well.

Note: For table descriptions (or DDL) lining up the column names, data
type names, and key/index information in neat columns is quite
helpful.

Note: If you know how to write DDL SQL (CREATE TABLE), please post
that (including constraints) instead of text descriptions. (Please
post only the portion of the DDL that is relevant.)


Example (text description):

MyTableOne
MyTableOneID AUTOINCREMENT PK
ColTwo INTEGER NOT NULL
ColThree TEXT(10)

MyTableTwo
MyTableTwoID AUTOINCREMENT PK\
MyTableOneID INTEGER PK/-- Composite Primary Key
FK -- MyTableOne MyTableOneID
ColThree INTEGER
ColFour DATETIME
ColFive CURRENCY
ColSix BIT
ColSeven TEXT(1)
ColEight TEXT(1)

etc., etc., etc.


Example (DDL SQL/CREATE TABLE):

CREATE TABLE MyTableOne
(MyTableOneID AUTOINCREMENT
,ColTwo INTEGER NOT NULL
,ColThree TEXT(10)
,CONSTRAINT pk_MyTableOne
PRIMARY KEY (MyTableOneID)
)

CREATE TABLE MyTableTwo
(MyTableTwoID AUTOINCREMENT
,MyTableOneID INTEGER
,ColThree INTEGER
,ColFour DATETIME
,ColFive CURRENCY
,ColSix BIT
,ColSeven TEXT(1)
,ColEight TEXT(1)
,CONSTRAINT pk_MyTableTwo
PRIMARY KEY (MyTableTwoID)
,CONSTRAINT fk_MyTableTwo_MyTableOne_MyTableOneID
FOREIGN KEY (MyTableOneID)
REFERENCES MyTableOne (MyTableOneID)
)

The Primary Key and Foreign Key notes (or constraints in the DDL SQL)
are *critical*.

Although it can be a source of information, please do not copy and
paste information directly from MS Access' Documenter. It is
virtually unreadable. If possible, do not use the Dcoumenter at all.
If you absolutely must use it, please distill down and legibly format
only the relevant table information.

-------------------------------

Sample Data (using comma delimited lists):

Note: If your sample data is "wide" across the screen, and you can't
trim out any columns because they are needed, make *two* (or more)
charts, and then clearly note that the second chart is the
continuation of the first chart for the same table. It is far easier
to convert a comma delimited chart into a table in MS Word or import
it directly into MS Excel (where the data can be copied and pasted
into a new table in MS Access) or even MS Access than it is to
manually undo the line-break on *every* row of a line-wrapped chart
(in fact, manually undoing the line-breaks caused by newsgroup posting
is a huge pain in the neck).

Note: In a comma delimited list, it is not absolutely necessary
(although it is nice) to have the data in the columns lined straight
up and down, like I have in my examples below. When the data is
finally imported into MS Access, a quick glance at the table in
datasheet view will show things lined up straight. It is not
necessary to expend extra effort on your chart here. (The right data
does have to be in the right position of each row of the chart, of
course.)

Note: Use the real table and column names whenever possible. Use
invented table names and column names (like I use below in my example)
only when you absolutely have to.

Note: When naming the columns on this chart, use the same column names
as is the table structures above. Using shortened names (or
completely different names, for whatever reason) may save space and
prevent line-wraps, but it can be severely confusing. If the chart
gets too "wide", make two (or more) charts if you have to, as noted
above in Table Structures.

Note: Please include just enough rows of sample data so that
sufficient tests of the various possibilities ("test cases") can be
made.

Note: Please do not attempt to post endless rows of data. 3-5 rows
are probably the minimum, and 10-20 row are probably the normal
maximum. (Post only what is necessary, and no more.)

Note: Please try and use real data when possible. However, real
people's personal information, or private information (banking,
proprietary, etc.), should never be posted. When you have information
that cannot be posted, you will have to invent test data that can
produce results similar to what the real data would produce.


MyTableOne
MyTableOneID, ColTwo, ColThree
1, 2, a
3, 4, b
5, 6, c

MyTableTwo (Part One)
MyTableTwoID, MyTableOneID, ColThree, ColFour, ColFive
1, 5, 1, 01/01/06, 1.01


MyTableTwo (Part Two)
ColSix, ColSeven, ColEight
-1, g, h

-------------------------------

Desired Results

.. . . <whatever it is you want your query to produce; "the right
stuff", if you will forgive the pun>

(Same chart style as found in the Sample Data section.)

-------------------------------

Query:

Your SQL query code attempts to date. (If "SQL code" throws you for a
loop, open your Query in Design View, and then use the menus, View >
SQL View, to switch to a window that will show the SQL code. Copy and
paste that into your new post to the newsgroup.)

Note: There is a huge temptation to merely copy and past the SQL code.
Usually, this is completely unreadable, and whoever reads it must
re-align the code in order to make heads or tails of it (yes, there
are a few out there who can read endless unbroken streams of code
packed together, but I am not one of them). If you know how, spend
some time straightening out and aligning the SQL before posting it.

Note: In some situations, of course, you will have no query or SQL
code at all.

-------------------------------

Current Results:

.. . . <the incorrect results the current query(s) is producing>

You may not have any current results if your query is not working or
if you have not been able to create a query so far.

(Same chart style as found in the Sample Data section.)

-------------------------------

I hope that the above can be of assistance in helping you receive an
answer to your various MS Access questions.


Sincerely,

Chris O.
 
G

GillWeb

response and count how many of each response there is.
Post your table structure - field names and datatype.
Post your query SQL. Open the query in design view, click on menu VIEW -
SQL View, highlight all, copy, and paste in a post.


Thanks for the explanation Karl - here is one of them:

SELECT [Attending Responses].[Question8 Non-A], Count([Attending
Responses].[Question8 Non-A]) AS [CountOfQuestion8 Non-A]
FROM [Attending Responses]
GROUP BY [Attending Responses].[Question8 Non-A];
 
G

GillWeb

Gillweb,

I echo Karl Dewey's comments.

Here's some more details that spell-out how to do this. It's quite
lengthy, but it has the information I believe you need.

The following contains information on how you can improve your chances
of getting your question answered:

-------------------------------

Formatting:

Please use a monospace font (Courier New, etc.) when writing out your
examples (all descriptions, charts, SQL, etc.).

-------------------------------

Process Description:

Please only include the shortest possible narrative of what is going
on with the query. (Include all that is necessary, and nothing more.)

When parts of your query make calculations, show the exact code or
nearest readable plain-text math formula you can create.

When you are done with this section, re-read it several times before
posting to assure yourself that you are accurately describing the
situation in a way you believe others will understand.

-------------------------------

Table Structures/Description:

Post a description of your table structures.

Open your table in Design View, view the column names and data types
in it, and then type out the column names and data types *that are
necessary* (do not include columns that are not absolutely necessary
for the query). Use the Index dialog box (you can get at it by
clicking on the "lightning bolt and stacked lines" icon on the
toolbar) to locate information on primary and foreign keys and other
indexes and type out that information, as well.

Note: For table descriptions (or DDL) lining up the column names, data
type names, and key/index information in neat columns is quite
helpful.

Note: If you know how to write DDL SQL (CREATE TABLE), please post
that (including constraints) instead of text descriptions. (Please
post only the portion of the DDL that is relevant.)

Example (text description):

MyTableOne
MyTableOneID AUTOINCREMENT PK
ColTwo INTEGER NOT NULL
ColThree TEXT(10)

MyTableTwo
MyTableTwoID AUTOINCREMENT PK\
MyTableOneID INTEGER PK/-- Composite Primary Key
FK -- MyTableOne MyTableOneID
ColThree INTEGER
ColFour DATETIME
ColFive CURRENCY
ColSix BIT
ColSeven TEXT(1)
ColEight TEXT(1)

etc., etc., etc.

Example (DDL SQL/CREATE TABLE):

CREATE TABLE MyTableOne
(MyTableOneID AUTOINCREMENT
,ColTwo INTEGER NOT NULL
,ColThree TEXT(10)
,CONSTRAINT pk_MyTableOne
PRIMARY KEY (MyTableOneID)
)

CREATE TABLE MyTableTwo
(MyTableTwoID AUTOINCREMENT
,MyTableOneID INTEGER
,ColThree INTEGER
,ColFour DATETIME
,ColFive CURRENCY
,ColSix BIT
,ColSeven TEXT(1)
,ColEight TEXT(1)
,CONSTRAINT pk_MyTableTwo
PRIMARY KEY (MyTableTwoID)
,CONSTRAINT fk_MyTableTwo_MyTableOne_MyTableOneID
FOREIGN KEY (MyTableOneID)
REFERENCES MyTableOne (MyTableOneID)
)

The Primary Key and Foreign Key notes (or constraints in the DDL SQL)
are *critical*.

Although it can be a source of information, please do not copy and
paste information directly from MS Access' Documenter. It is
virtually unreadable. If possible, do not use the Dcoumenter at all.
If you absolutely must use it, please distill down and legibly format
only the relevant table information.

-------------------------------

Sample Data (using comma delimited lists):

Note: If your sample data is "wide" across the screen, and you can't
trim out any columns because they are needed, make *two* (or more)
charts, and then clearly note that the second chart is the
continuation of the first chart for the same table. It is far easier
to convert a comma delimited chart into a table in MS Word or import
it directly into MS Excel (where the data can be copied and pasted
into a new table in MS Access) or even MS Access than it is to
manually undo the line-break on *every* row of a line-wrapped chart
(in fact, manually undoing the line-breaks caused by newsgroup posting
is a huge pain in the neck).

Note: In a comma delimited list, it is not absolutely necessary
(although it is nice) to have the data in the columns lined straight
up and down, like I have in my examples below. When the data is
finally imported into MS Access, a quick glance at the table in
datasheet view will show things lined up straight. It is not
necessary to expend extra effort on your chart here. (The right data
does have to be in the right position of each row of the chart, of
course.)

Note: Use the real table and column names whenever possible. Use
invented table names and column names (like I use below in my example)
only when you absolutely have to.

Note: When naming the columns on this chart, use the same column names
as is the table structures above. Using shortened names (or
completely different names, for whatever reason) may save space and
prevent line-wraps, but it can be severely confusing. If the chart
gets too "wide", make two (or more) charts if you have to, as noted
above in Table Structures.

Note: Please include just enough rows of sample data so that
sufficient tests of the various possibilities ("test cases") can be
made.

Note: Please do not attempt to post endless rows of data. 3-5 rows
are probably the minimum, and 10-20 row are probably the normal
maximum. (Post only what is necessary, and no more.)

Note: Please try and use real data when possible. However, real
people's personal information, or private information (banking,
proprietary, etc.), should never be posted. When you have information
that cannot be posted, you will have to invent test data that can
produce results similar to what the real data would produce.

MyTableOne
MyTableOneID, ColTwo, ColThree
1, 2, a
3, 4, b
5, 6, c

MyTableTwo (Part One)
MyTableTwoID, MyTableOneID, ColThree, ColFour, ColFive
1, 5, 1, 01/01/06, 1.01

MyTableTwo (Part Two)
ColSix, ColSeven, ColEight
-1, g, h

-------------------------------

Desired Results

. . . <whatever it is you want your query to produce; "the right
stuff", if you will forgive the pun>

(Same chart style as found in the Sample Data section.)

-------------------------------

Query:

Your SQL query code attempts to date. (If "SQL code" throws you for a
loop, open your Query in Design View, and then use the menus, View >
SQL View, to switch to a window that will show the SQL code. Copy and
paste that into your new post to the newsgroup.)

Note: There is a huge temptation to merely copy and past the SQL code.
Usually, this is completely unreadable, and whoever reads it must
re-align the code in order to make heads or tails of it (yes, there
are a few out there who can read endless unbroken streams of code
packed together, but I am not one of them). If you know how, spend
some time straightening out and aligning the SQL before posting it.

Note: In some situations, of course, you will have no query or SQL
code at all.

-------------------------------

Current Results:

. . . <the incorrect results the current query(s) is producing>

You may not have any current results if your query is not working or
if you have not been able to create a query so far.

(Same chart style as found in the Sample Data section.)

-------------------------------

I hope that the above can be of assistance in helping you receive an
answer to your various MS Access questions.

Sincerely,

Chris O.- Hide quoted text -

- Show quoted text -

Thanks Chris O - I shall print that off & study it till I get it all!
 
G

Guest

Post your table structure - field names and datatype.
How many times mus I ask for the same thing?
I think I know the answer to your problem. If you will not post your table
structure then search on question and response I gave to --
webedz
microsoft.public.access.gettingstarted -
Subject - New and Not Sure Where to Start.
--
KARL DEWEY
Build a little - Test a little


GillWeb said:
response and count how many of each response there is.
Post your table structure - field names and datatype.
Post your query SQL. Open the query in design view, click on menu VIEW -
SQL View, highlight all, copy, and paste in a post.


Thanks for the explanation Karl - here is one of them:

SELECT [Attending Responses].[Question8 Non-A], Count([Attending
Responses].[Question8 Non-A]) AS [CountOfQuestion8 Non-A]
FROM [Attending Responses]
GROUP BY [Attending Responses].[Question8 Non-A];
 
J

John Spencer

You might try a crosstab query and designating the response columns

TRANSFORM CLng(NZ(Count([Question8 Non-A]),0)) as ResponseCount
SELECT "Answer Count"
FROM [Attending Responses]
GROUP BY "Answer Count"
PIVOT [Question8 Non-A] IN ("Strongly Agree", "Agree", "Disagree", "Strongly
Disagree")

As I noted in an earlier response, the need to do something like this is
because your table structure is not "correct". Since your list of responses
for each question is buried in the list attached to each question in the
table.

Duane Hookom has a sample survey database at

http://rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane

This fully functional application uses a small collection of tables,
queries, forms, reports, and code to manage multiple surveys. Users can
create a survey, define questions, enter pre-defined answers, limit to list,
report results, create crosstabs, and other features without changing the
design of any objects.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

GillWeb said:
response and count how many of each response there is.
Post your table structure - field names and datatype.
Post your query SQL. Open the query in design view, click on menu VIEW -
SQL View, highlight all, copy, and paste in a post.


Thanks for the explanation Karl - here is one of them:

SELECT [Attending Responses].[Question8 Non-A], Count([Attending
Responses].[Question8 Non-A]) AS [CountOfQuestion8 Non-A]
FROM [Attending Responses]
GROUP BY [Attending Responses].[Question8 Non-A];
 
G

GillWeb

I think she doesn't know we're talking about (yet).

Sincerely,

Chris O.

You got it Chris O!
I thought I'd posted just what I was asked to do, following the
instructions from Karl, but obviously not.

I think I'll simply paste my query results into Excel & add the
missing responses that way! It HAS to be easier than all this
confusion!

I'm going to check out the sample suggested & linked by John Spencer &
see if I get any further.

I really appreciate you all for your efforts trying to help me & I'm
sorry that I'm not "getting it" - I know how frustrating it is when
somebody doesn't undertand what you're trying to tell them :-(
 
C

Chris2

GillWeb said:
You got it Chris O!
I thought I'd posted just what I was asked to do, following the
instructions from Karl, but obviously not.

I think I'll simply paste my query results into Excel & add the
missing responses that way! It HAS to be easier than all this
confusion!

I'm going to check out the sample suggested & linked by John Spencer &
see if I get any further.

I really appreciate you all for your efforts trying to help me & I'm
sorry that I'm not "getting it" - I know how frustrating it is when
somebody doesn't undertand what you're trying to tell them :-(

Gillweb,

That depends on how much of your time it will take. If you're going
to do this once, then just get it over with. If this is ongoing, you
are about to chain yourself down.

A couple of good books to glance at in a bookstore:

Database Design for Mere Mortals by Michael J. Hernandez

SQL Queries for Mere Mortals by Michael J. Hernandez, John L. Viescas


Sincerely,

Chris O.
 

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