PC Review


Reply
Thread Tools Rate Thread

Crosstab query totals

 
 
ripper
Guest
Posts: n/a
 
      22nd May 2010
I have Query1 that returns 2 fields:
CatID
Step1Decision

CatID can be 01 thru 29
Step1Decision can be N,X,P,D,R

Query1:
SELECT qryGrievances.CatID, qryGrievances.Step1Decision
FROM qryGrievances, qryStartEnd

Query2 uses Query1 joined to qryCategories to return all the categories and
their description plus those in Query1

Query2:
SELECT qryCategories.CatID, qryCategories.CatDesc, Query1.Step1Decision
FROM qryCategories LEFT JOIN Query1 ON qryCategories.CatID = Query1.CatID

Query3 uses Query2 in a crosstab so the Step1Decision (N,X,P,D,R) become
column headings and categories become rows, and adds a Total field:

Query3:
TRANSFORM Count(Query2.Step1Decision) AS [Count]
SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
FROM Query2
GROUP BY Query2.CatID, Query2.CatDesc
PIVOT Query2.Step1Decision

Result looks like this:

CatID CatDesc Total <> D N R X
01 Accounting 7 6 1
02 Assignments 24 5 12 7
03 Conditions 1 0
04 Disciplinary 2 2

My questions are: how is the <> field generated? I can't refer to it in
code, which is a problem. Also, why does the total column show correct
totals for the D,N,R,X values added across, but if there are no records
returned for a category, it still shows 1? Also, if no records exist for one
of the decision values (P in the case above), that field is not returned by
the query at all. How can I create a report based on a query that may or may
not return some of the fields?

Thanks to all who can help!
Ripper


 
Reply With Quote
 
 
 
 
KARL DEWEY
Guest
Posts: n/a
 
      23rd May 2010
<> represents the Null fields of the left join with query1.

This is untested but try it --
Query2:
SELECT qryCategories.CatID, qryCategories.CatDesc, Nz(Query1.Step1Decision,
"None") AS Decision
FROM qryCategories LEFT JOIN Query1 ON qryCategories.CatID = Query1.CatID;

Query3:
TRANSFORM Count(Query2.Step1Decision) AS [Count]
SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
FROM Query2
GROUP BY Query2.CatID, Query2.CatDesc
PIVOT Query2.Decision;

--
Build a little, test a little.


"ripper" wrote:

> I have Query1 that returns 2 fields:
> CatID
> Step1Decision
>
> CatID can be 01 thru 29
> Step1Decision can be N,X,P,D,R
>
> Query1:
> SELECT qryGrievances.CatID, qryGrievances.Step1Decision
> FROM qryGrievances, qryStartEnd
>
> Query2 uses Query1 joined to qryCategories to return all the categories and
> their description plus those in Query1
>
> Query2:
> SELECT qryCategories.CatID, qryCategories.CatDesc, Query1.Step1Decision
> FROM qryCategories LEFT JOIN Query1 ON qryCategories.CatID = Query1.CatID
>
> Query3 uses Query2 in a crosstab so the Step1Decision (N,X,P,D,R) become
> column headings and categories become rows, and adds a Total field:
>
> Query3:
> TRANSFORM Count(Query2.Step1Decision) AS [Count]
> SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
> FROM Query2
> GROUP BY Query2.CatID, Query2.CatDesc
> PIVOT Query2.Step1Decision
>
> Result looks like this:
>
> CatID CatDesc Total <> D N R X
> 01 Accounting 7 6 1
> 02 Assignments 24 5 12 7
> 03 Conditions 1 0
> 04 Disciplinary 2 2
>
> My questions are: how is the <> field generated? I can't refer to it in
> code, which is a problem. Also, why does the total column show correct
> totals for the D,N,R,X values added across, but if there are no records
> returned for a category, it still shows 1? Also, if no records exist for one
> of the decision values (P in the case above), that field is not returned by
> the query at all. How can I create a report based on a query that may or may
> not return some of the fields?
>
> Thanks to all who can help!
> Ripper
>
>
> .
>

 
Reply With Quote
 
 
 
 
Duane Hookom
Guest
Posts: n/a
 
      24th May 2010
The <> is generated from one or more records with no value in Step1Decision
field.

TRANSFORM Count(Query2.Step1Decision) AS [Count]
SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
FROM Query2
GROUP BY Query2.CatID, Query2.CatDesc
PIVOT Query2.Step1Decision IN ("D","N","R","X","P");

--
Duane Hookom
MS Access MVP


"ripper" <(E-Mail Removed)> wrote in message
news:uyHhrff#(E-Mail Removed)...
> I have Query1 that returns 2 fields:
> CatID
> Step1Decision
>
> CatID can be 01 thru 29
> Step1Decision can be N,X,P,D,R
>
> Query1:
> SELECT qryGrievances.CatID, qryGrievances.Step1Decision
> FROM qryGrievances, qryStartEnd
>
> Query2 uses Query1 joined to qryCategories to return all the categories
> and their description plus those in Query1
>
> Query2:
> SELECT qryCategories.CatID, qryCategories.CatDesc, Query1.Step1Decision
> FROM qryCategories LEFT JOIN Query1 ON qryCategories.CatID = Query1.CatID
>
> Query3 uses Query2 in a crosstab so the Step1Decision (N,X,P,D,R) become
> column headings and categories become rows, and adds a Total field:
>
> Query3:
> TRANSFORM Count(Query2.Step1Decision) AS [Count]
> SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
> FROM Query2
> GROUP BY Query2.CatID, Query2.CatDesc
> PIVOT Query2.Step1Decision
>
> Result looks like this:
>
> CatID CatDesc Total <> D N R X
> 01 Accounting 7 6 1
> 02 Assignments 24 5 12 7
> 03 Conditions 1 0
> 04 Disciplinary 2 2
>
> My questions are: how is the <> field generated? I can't refer to it in
> code, which is a problem. Also, why does the total column show correct
> totals for the D,N,R,X values added across, but if there are no records
> returned for a category, it still shows 1? Also, if no records exist for
> one of the decision values (P in the case above), that field is not
> returned by the query at all. How can I create a report based on a query
> that may or may not return some of the fields?
>
> Thanks to all who can help!
> Ripper
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      24th May 2010
The reason the Total is 1 when there are no records in Step1Decision is you
are counting CatID in the SELECT clause. Try counting Step1Decision instead.


TRANSFORM Count(Query2.Step1Decision) AS [Count]
SELECT Query2.CatID, Query2.CatDesc, Count(Query2.Step1Decision) AS Total
FROM Query2
GROUP BY Query2.CatID, Query2.CatDesc
PIVOT Query2.Step1Decision IN ("D","N","R","X","P");

Of course, the Total count could still be off if there were any other values
in Step1decision other than Null, D, N, R, X, or P.

So you might even have to limit the query a bit further with a where clause.
TRANSFORM Count(Query2.Step1Decision) AS [Count]
SELECT Query2.CatID, Query2.CatDesc, Count(Query2.Step1Decision) AS Total
FROM Query2
WHERE Query2.Step1Decision IN ("D","N","R","X","P") OR Step1Decision is Null
GROUP BY Query2.CatID, Query2.CatDesc
PIVOT Query2.Step1Decision IN ("D","N","R","X","P");


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Duane Hookom wrote:
> The <> is generated from one or more records with no value in
> Step1Decision field.
>
> TRANSFORM Count(Query2.Step1Decision) AS [Count]
> SELECT Query2.CatID, Query2.CatDesc, Count(Query2.CatID) AS Total
> FROM Query2
> GROUP BY Query2.CatID, Query2.CatDesc
> PIVOT Query2.Step1Decision IN ("D","N","R","X","P");
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crosstab query is no longer crosstab when I include field (in repo Ben8765 Microsoft Access Reports 1 15th Oct 2009 10:01 PM
Crosstab query - want report to look like crosstab alison.justice Microsoft Access Queries 1 31st May 2009 05:35 AM
Pivot Totals: Group totals different from Grand totals PsyberFox Microsoft Excel Misc 1 13th Feb 2008 07:16 PM
Crosstab form based on Crosstab query? Penny Microsoft Access Forms 1 31st Mar 2006 07:36 PM
Crosstab query with criteria, dynamic columns and crosstab report question joshblair Microsoft Access Queries 5 13th Jan 2006 10:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:53 PM.