Hi Duane,
Yes, and I have accomplished that, but I need more. Ignore the question
about null values; we are not going to allow nulls.
Let me back up a bit and make sure I am making myself clear. There are
varying number of reviews for each county. In the original database, each
record (or row) is one review identified by ReviewKey, and each question is a
field (or column heading).
Your recommendation for a union query was very helpful. The fields in the
union query are CNTYNAME, ReviewKey, Question, and Answer. I then created a
crosstab query using the union query. Using the Union Crosstab Query in the
report resulted in a table format with each county name as a column heading
and a row for each answer with the count for each response. I’ve tried to
show and example below.
CountyA CountyB
A1-1 9 1
A1-2 10 5
A1-3 25 39
A1-4 4 2
A2-1 (etc)
This is fine so far, but I also need to have another column under each
county to show the percentage of total reviews per county for each response.
For example, the total number of reviews [CountOfReviewKey] for CountyA is
12; divided by 9 that answered 1 to question A1; is 75%.
CountOfReviewKey comes from a SELECT DISTINCT on CNTYNAME query. It has
only 2 fields; CNTYNAME and CountOfReviewKey. I would prefer to have the
CountOfReviewKey display on the report, but it’s not critical. But I can’t
find a way to use this with the crosstab query on the report.
In the report, the county names are in the page header and the question
number is in a question header with the answer options in the detail section.
I tried adding a text box in the detail beside the answer text box in the
detail section with the control source set to =([CountyA/12)*100. This gives
the correct answer for each answer, but not very practical when the next
report with different counties has to be done. I tried using a calculation
in the control source, =[CountyA]/([qReview
Count].[CountOfReviewKey]=([qReview Count].[CNTYNAME]="CountyA")), which
didn’t work and it still required “hard coding†the county name.
Please let me know if you have suggestions for other ways to create both
count and percentage columns on the report.
Thanks much.
Duane Hookom said:
Apparently you need every answer for every question for every CNTYNAME? If
this is the case, I think you need to union your 6 lookup tables with a
derived column that matches the question value ie: A1a, A1b,...etc. Then
create a cartesian query that select every distinct CNTYNAME with every
distinct value in the new union query.
I don't know what your lookup tables are named or their structure. I also
would expect you to have a table with a record for each CNTYNAME.
--
Duane Hookom
Microsoft Access MVP
jmoore said:
Could you please explain what a cartesian query is, and how I would use that
with the union query.
Thank you.
:
The typical method of displaying the Null records is to create a cartesian
query that includes all distinct possible values. For instance if you have a
table of Shapes and a table of Colors and want to get all combinations of
Shapes and Colors, the query might look like:
--- qcarColorsShapes ---
SELECT DISTINCT [Color], [Shape]
FROM tblColors, tblShapes;
You can then use this cartesian query (qcarColorsShapes) in another with a
join that includes all of the records from qcarColorsShapes.
--
Duane Hookom
Microsoft Access MVP
:
Sorry for the duplicate posts. I tried several times because I received a
message that it was unsuccessful when I submitted. I tried another one later
that apparently did not go through. I revised the code to use a query. This
is better because I don't need all records in the 2007 Sample table. Will
using a query create any difficulties?
I then created another query based on the union query. I set the Total row
to Group By for CNTYNAME, Question and Answer fields. I added a second
Answer field and set it to Count. This produces the required results (# of
responses for each answer option (1, 2, 3 or 9) for each question by county
(e.g., For countyA there were 22 that answered 1, one that answered 2 and one
who answered 3 to question A1a. So far, good. However, the null responses
are not counted. There is a row for question A1a with a null value in the
answer column, with the count of zero.
Is it possible to produce a count of null values?
SELECT [2007 Sample].CNTYNAME, [tReview].ReviewKey, "A1a" as Question, [A1a]
as Answer
FROM [qReview Sample]
UNION ALL
SELECT [2007 Sample].CNTYNAME, [tReview].ReviewKey, "A1b" as Question, [A1b]
as Answer
FROM [qReview Sample]
UNION ALL SELECT [2007 Sample].CNTYNAME, [tReview].ReviewKey, "A2" as
Question, [A2] as Answer
FROM [qReview Sample];
Thanks very much for all of your help.
:
The AN is just a place holder for the last field in your table since I didn't
know what your field names were.
You should be able to link the union query to the table with the county in
it. This might require adding another field to each section of the union
query.