dbTalk Databases Forums  

Crosstab and missing category

comp.databases.ms-access comp.databases.ms-access


Discuss Crosstab and missing category in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bezz
 
Posts: n/a

Default Crosstab and missing category - 03-23-2011 , 12:44 PM






I have got a routine to store statistics of document status on a weekly basis to identify trends. There are several status points
of documents, for example, Not Written, Draft, Preview, In Work, Complete, Under Evaluation, Completed.

These are also spread across 4 departments. I use a straightforward select query to detemine status, then a crosstab based on that
query to count the number of documents at a certain status within each department. The routine then checks to see if an update
already has been made that week, if so deletes the week concerned and updates via an append query based on the crosstab, and if not
already saved (i.e. first occurence) just runs the append query.

The problem arises where for a given week, there are no documents in a particular category, i.e. draft, in which case the fields
are not created in the append query and there is an error generated.

I relaise that a more longwinded way of doing this is through Dcount, and Nz but that would be a lot more complicated and not very
elegant. Is there any way to make a crosstab work around base fields and have the contents as zero if they are?

Thanks

Bz


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #2  
Old   
black nebraska
 
Posts: n/a

Default Re: Crosstab and missing category - 03-23-2011 , 01:49 PM






On Mar 23, 1:44*pm, bezz <b... (AT) hotmail (DOT) com> wrote:
Quote:
I have got a routine to store statistics of document status on a weekly basis to identify trends. *There are several status points
of documents, for example, Not Written, Draft, Preview, In Work, Complete, Under Evaluation, Completed.

These are also spread across 4 departments. *I use a straightforward select query to detemine status, then a crosstab based on that
query to count the number of documents at a certain status within each department. *The routine then checks to see if an update
already has been made that week, if so deletes the week concerned and updates via an append query based on the crosstab, and if not
already saved (i.e. first occurence) just runs *the append query.

The problem arises where for a given week, there are no documents in a particular category, i.e. draft, in which case the fields
are not created in the append query and there is an error generated.

I relaise that a more longwinded way of doing this is through Dcount, andNz but that would be a lot more complicated and not very
elegant. *Is there any way to make a crosstab work around base fields and have the contents as zero if they are?

Thanks

Bz

--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
I believe you just need edit the column headings property of the query
so you'd end up with:
"Not Written", "Draft", "Preview", "In Work", "Complete", "Under
Evaluation", "Completed"

Reply With Quote
  #3  
Old   
bezz
 
Posts: n/a

Default Re: Crosstab and missing category - 03-23-2011 , 01:57 PM



The column headings won't work as the cross tab reads the status and department and then counts number of each category against
each department. If there are zero to count then it doesn't read the category?

Bz


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #4  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Crosstab and missing category - 03-23-2011 , 02:25 PM



bezz wrote:
Quote:
I have got a routine to store statistics of document status on a
weekly basis to identify trends. There are several status points of
documents, for example, Not Written, Draft, Preview, In Work,
Complete, Under Evaluation, Completed.

These are also spread across 4 departments. I use a straightforward
select query to detemine status, then a crosstab based on that query
to count the number of documents at a certain status within each
department. The routine then checks to see if an update already has
been made that week, if so deletes the week concerned and updates via
an append query based on the crosstab, and if not already saved (i.e.
first occurence) just runs the append query.

The problem arises where for a given week, there are no documents in
a particular category, i.e. draft, in which case the fields are not
created in the append query and there is an error generated.

I relaise that a more longwinded way of doing this is through Dcount,
and Nz but that would be a lot more complicated and not very elegant.
Is there any way to make a crosstab work around base fields and have
the contents as zero if they are?

Thanks

Bz
Another way that does not involve Dcount and Nz is an aggregate query (you
do not need to use TRANSFORM to do a crosstab ...):

select Week, Department,
Sum(Iif([Status="Not Written",1,0)) as [Not Written],
Sum(Iif([Status="Draft",1,0)) as [Draft],
etc.
From YourStatusQuery
Group By Week, Department

Since you know the various categories at design time, you don't need to use
the Crosstab Query wizard.

Reply With Quote
  #5  
Old   
black nebraska
 
Posts: n/a

Default Re: Crosstab and missing category - 03-23-2011 , 02:39 PM



On Mar 23, 2:57*pm, bezz <b... (AT) hotmail (DOT) com> wrote:
Quote:
The column headings won't work as the cross tab reads the status and department and then counts number of each category against
each department. If there are zero to count then it doesn't read the category?

Bz

--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
I was pretty sure the column header property was linked to the 'pivot
column in ('value1','value2')' clause in the sql thats generated for a
crosstab, but if thats not the case then the format of the sql for the
crosstab needs to be:

TRANSFORM aggfunction
selectstatement
PIVOT pivotfield [IN (value1[, value2[, ...]])]

http://office.microsoft.com/en-us/ac...001032277.aspx

that should create the column counts for the values named regardless
of the count of the values.

Reply With Quote
  #6  
Old   
John Spencer
 
Posts: n/a

Default Re: Crosstab and missing category - 03-23-2011 , 05:38 PM



The column headings will work. The column headings should be the different
values that are in category.

Something like the following

TRANSFORM CLong(Nz(Count(Documents),0)) as TheValue
SELECT Department
FROM [YourTable]
WHERE StatusDate Between #1/1/2011# and #1/7/2011#
GROUP BY Department
PIVOT Category IN ("Not Written","Draft","Preview", "In
Work","Completed","Under Evaulation")

Just enter all the relevant values in the In clause of Pivot phrase. If there
is a status that is not relevant to the period, it will still show up in the
results with zero as the number of documents.

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

On 3/23/2011 3:57 PM, bezz wrote:
Quote:
The column headings won't work as the cross tab reads the status and department and then counts number of each category against
each department. If there are zero to count then it doesn't read the category?

Bz


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.