Ask Experts Questions for FREE Help !
Ask
    jakester's Avatar
    jakester Posts: 582, Reputation: 165
    Senior Member
     
    #1

    Jul 27, 2009, 01:38 PM
    Grouping by Month in Crosstab Query
    Hello -

    here's my problem. I'm trying to put together a crosstab query that groups admit dates to the hospital by month for a particular nursing home. Here's how I have set it up so far:

    I have Admit date set as the column heading for the crosstab query. I have nursing home facility set as the row heading and I have admit date set as the value. What I am attempting to do is count the number of admissions to a nursing home for each month.

    This is the way the crosstab appears when I run it:

    Nursing Home 10/10/08 10/15/08 10/17/08 11/5/08 11/17/08
    XYZ Home 1 1
    Fountain of Life 1 1 1
    Last Days 1 1 1

    Can I group the months together so that I see the admit dates rolled up into 1 month? So, I'd like to see:

    Nursing Home 10-08 11-08
    XYZ Home --------- 2 ------
    Fountain of Life----- 2 ------ 1
    Last Days --------- 2 ------- 1

    I've looked at countless ways in which people have attempted to group dates together in access but no one has attempted a similar problem so I'm stuck.

    Can anyone help? Sorry, but I can't get the formatting in the body of this question to cooperate. The counts for each date don't line up accordingly but hopefully you get that there are 2 admits per nursing home in Oct and 1 admit for November for 2 out of the 3.

    Thanks.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    Jul 27, 2009, 03:12 PM
    When you use the crosstab wizard (and I just tried this) if you select a date field as the Column headings, it asks for an Interval (of which month is a choice). That should do it.

    By the way, I wouldn't count the date field, I would count the PK field.
    jakester's Avatar
    jakester Posts: 582, Reputation: 165
    Senior Member
     
    #3

    Aug 3, 2009, 12:28 PM
    Quote Originally Posted by ScottGem View Post
    When you use the crosstab wizard (and I just tried this) if you select a date field as the Column headings, it asks for an Interval (of which month is a choice). That should do it.

    By the way, I wouldn't count the date field, I would count the PK field.
    Scott -

    Ok, I got this to work for grouping by month. But then I encountered another problem which I hadn't contemplated. My records are being grouped together by month, regardless of the year the record takes place in. So I created a Format function to include year in the results. That kept records by month in their correct year buckets.

    The problem I have now is that the columns are sorted in alphabetical order. For example:

    Apr-08 -- Dec-08 -- Feb-09 -- Jan-09

    Ideally, I'd like to keep the columns formatted chronologically. Anyway, to do that?

    Here's my SQL code if that helps:

    TRANSFORM Count([IDE - 2009].[Admit Date]) AS [CountOfAdmit Date]
    SELECT [IDE - 2009].[Service Facility], Count([IDE - 2009].LineOfBusiness) AS [Total Admits]
    FROM [IDE - 2009]
    GROUP BY [IDE - 2009].[Service Facility]
    ORDER BY Format([Admit Date],"mmm-yy")
    PIVOT Format([Admit Date],"mmm-yy")
    WITH OWNERACCESS OPTION;

    Thanks to you or anyone who can help.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #4

    Aug 3, 2009, 01:10 PM

    Were you using a Date field? For the column headings? If you want nt to compare years, you can setup levels of intervals. You can set it to display all the months within a year or all the motnsh for each year side by side.

    Ex:
    2009
    Jan Feb Mar etc

    Jan
    2008 2009

    It just depends on the order you setup.

    You do NOT need to format a date in your query and in fact shouldn't because you won't get chrono order.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search


Check out some similar questions!

Factor by Grouping [ 5 Answers ]

I understand the idea of factoring by grouping for the most part, but some of the answers in the back of the book are baffling me. Ex) 6x3 + 9x2 - 2x2 - 3x =(6x3 + 9x2) - (2x2 - 3x) =3x2(2x + 3) - 1(2x + 3) My answer: (2x + 3)(3x - 1) Book answer: x(2x + 3)(3x - 1)

Landlord Requiring 2 month Vacating Notice on 3 month (month to month) lease [ 21 Answers ]

I am in a situation and am in need of some advice. I am currently renting an apartment in Minneapolis. I am doing an internship which only requires me to live here for 3 Months. I signed a lease with a complex on a month to month basis. I planned to Move out at the end of April, so on march 1 I...

Basis of Grouping of shares . [ 1 Answers ]

1.What is the basis of grouping of shares in different groups for ex. A group etc..

Crosstab Query in MS Access [ 1 Answers ]

How can I change the my query to crosstab query.. please see the picture.. http://www.l22l.com/l22l-up-1/8a7081adec.jpg I write this code... how can I change to a crosstab query SELECT SeaTable.location, Count(SeaTable.location) AS CountOflocation FROM SSFMainTable INNER JOIN SeaTable...


View more questions Search