need totals from all days in a month in one place

A

AccessNeophyte

Hi All,

I'v browsed this group for an answer to this, with no success.

This is my situation:
I need to end up with the number of days during a given month on which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.

I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"

Is there an expression(s) that will give me the total from Col D?

Thanks,
Liz
 
J

John Spencer

SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")


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

AccessNeophyte

SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")

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


I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -

- Show quoted text -

Thanks John - I always enjoy your posts.

You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?

Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.

If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate

Thanks,
Liz
 
J

John Spencer

Ok, your original posting indicated that you already had calculated the
number of residents in the facility on each date. Your fields don't
indicate that.

SO the first question is have you already calculated the number of
people in the facility for each day. Or are you planning to calculate
them using the AdmitDate and Discharge Date? If so, do you have a table
of dates in your database?

I hesitate to go any further with a solution until I understand more
about your data.

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

SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")

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


Hi All,
I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
0.9,1,0)
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -
- Show quoted text -

Thanks John - I always enjoy your posts.

You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?

Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.

If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate

Thanks,
Liz
 
A

AccessNeophyte

Ok, your original posting indicated that you already had calculated the
number of residents in the facility on each date. Your fields don't
indicate that.

SO the first question is have you already calculated the number of
people in the facility for each day. Or are you planning to calculate
them using the AdmitDate and Discharge Date? If so, do you have a table
of dates in your database?

I hesitate to go any further with a solution until I understand more
about your data.

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


SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
Hi All,
I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
0.9,1,0)
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -
- Show quoted text -
Thanks John - I always enjoy your posts.
You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?
Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.
If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate
Thanks,
Liz- Hide quoted text -

- Show quoted text -

SO the first question is have you already calculated the number of
people in the facility for each day.
Liz - No

Or are you planning to calculate them using the AdmitDate and
Discharge Date?
Liz - Hoping to, yes.

If so, do you have a table of dates in your database?
Liz - Unclear what you mean by "table of dates." I have fields in my
"Client Data" table for AdmitDate & DischargeDate. I don't think
that's what you mean, though.
 
J

John Spencer

Sorry to take so long, but I've been trying to come up with a simple
solution and I am not having any luck.

My solution involves adding a new table that contains one column.
Table: tDates
Field: fDate

You need one record in that table for every date in the time period you are
interested in.

Then you can use a query to create a "record" for each day and then get a
count for each date

--Add your table and the tDates table to a new query
--Add BMC_ID and fDate to the fields
--Under fDate enter the followng as criteria
Between AdmitDate and DischargeDate
-- Select Query: Totals from the menu
-- Change GROUP BY to Count for BMC_ID
-- Change GROUP BY to WHERE under fDate
-- Add fDate to the query again.

That will give you a count for each day.. Save this query as qBase

Now using Qbase as the source for the next query.
-- Add Qbase to the query
-- Add fDate and CountOfBMC_ID to the query
-- Add fDate again
-- select Query: Totals
-- Change Group by to COUNT under one of the Fdate
-- Change to other Fdate to Format(qBase.Fdate,"yyyy-mm")
-- Change Group By to WHERE under CountOfBM_ID and
-- Enter the criteria

I think that will give you the information you are looking for.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

AccessNeophyte said:
Ok, your original posting indicated that you already had calculated the
number of residents in the facility on each date. Your fields don't
indicate that.

SO the first question is have you already calculated the number of
people in the facility for each day. Or are you planning to calculate
them using the AdmitDate and Discharge Date? If so, do you have a table
of dates in your database?

I hesitate to go any further with a solution until I understand more
about your data.

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


SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
Hi All,
I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on
which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
0.9,1,0)
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -
- Show quoted text -
Thanks John - I always enjoy your posts.
You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?
Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.
If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate
Thanks,
Liz- Hide quoted text -

- Show quoted text -

SO the first question is have you already calculated the number of
people in the facility for each day.
Liz - No

Or are you planning to calculate them using the AdmitDate and
Discharge Date?
Liz - Hoping to, yes.

If so, do you have a table of dates in your database?
Liz - Unclear what you mean by "table of dates." I have fields in my
"Client Data" table for AdmitDate & DischargeDate. I don't think
that's what you mean, though.
 
A

AccessNeophyte

Sorry to take so long, but I've been trying to come up with a simple
solution and I am not having any luck.

My solution involves adding a new table that contains one column.
Table: tDates
Field: fDate

You need one record in that table for every date in the time period you are
interested in.

Then you can use a query to create a "record" for each day and then get a
count for each date

--Add your table and the tDates table to a new query
--Add BMC_ID and fDate to the fields
--Under fDate enter the followng as criteria
Between AdmitDate and DischargeDate
-- Select Query: Totals from the menu
-- Change GROUP BY to Count for BMC_ID
-- Change GROUP BY to WHERE under fDate
-- Add fDate to the query again.

That will give you a count for each day.. Save this query as qBase

Now using Qbase as the source for the next query.
-- Add Qbase to the query
-- Add fDate and CountOfBMC_ID to the query
-- Add fDate again
-- select Query: Totals
-- Change Group by to COUNT under one of the Fdate
-- Change to other Fdate to Format(qBase.Fdate,"yyyy-mm")
-- Change Group By to WHERE under CountOfBM_ID and
-- Enter the criteria

I think that will give you the information you are looking for.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.




Ok, your original posting indicated that you already had calculated the
number of residents in the facility on each date. Your fields don't
indicate that.
SO the first question is have you already calculated the number of
people in the facility for each day. Or are you planning to calculate
them using the AdmitDate and Discharge Date? If so, do you have a table
of dates in your database?
I hesitate to go any further with a solution until I understand more
about your data.
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
Hi All,
I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on
which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
0.9,1,0)
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -
- Show quoted text -
Thanks John - I always enjoy your posts.
You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?
Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.
If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate
Thanks,
Liz- Hide quoted text -
- Show quoted text -
SO the first question is have you already calculated the number of
people in the facility for each day.
Liz - No
Or are you planning to calculate them using the AdmitDate and
Discharge Date?
Liz - Hoping to, yes.
If so, do you have a table of dates in your database?
Liz - Unclear what you mean by "table of dates." I have fields in my
"Client Data" table for AdmitDate & DischargeDate. I don't think
that's what you mean, though.- Hide quoted text -

- Show quoted text -

Thanks John,

Is there a simple way to enter all the dates from 1/1/2007 forward
into this table? I can't find anything helpful in Help or in
microsoft.public.access.tabledesign.

Liz
 
A

AccessNeophyte

Sorry to take so long, but I've been trying to come up with a simple
solution and I am not having any luck.
My solution involves adding a new table that contains one column.
Table: tDates
Field: fDate
You need one record in that table for every date in the time period you are
interested in.
Then you can use a query to create a "record" for each day and then get a
count for each date
--Add your table and the tDates table to a new query
--Add BMC_ID and fDate to the fields
--Under fDate enter the followng as criteria
Between AdmitDate and DischargeDate
-- Select Query: Totals from the menu
-- Change GROUP BY to Count for BMC_ID
-- Change GROUP BY to WHERE under fDate
-- Add fDate to the query again.
That will give you a count for each day.. Save this query as qBase
Now using Qbase as the source for the next query.
-- Add Qbase to the query
-- Add fDate and CountOfBMC_ID to the query
-- Add fDate again
-- select Query: Totals
-- Change Group by to COUNT under one of the Fdate
-- Change to other Fdate to Format(qBase.Fdate,"yyyy-mm")
-- Change Group By to WHERE under CountOfBM_ID and
-- Enter the criteria
I think that will give you the information you are looking for.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.
Ok, your original posting indicated that you already had calculated the
number of residents in the facility on each date. Your fields don't
indicate that.
SO the first question is have you already calculated the number of
people in the facility for each day. Or are you planning to calculate
them using the AdmitDate and Discharge Date? If so, do you have a table
of dates in your database?
I hesitate to go any further with a solution until I understand more
about your data.
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
SELECT Format([Date],"yyyy-mm")
, Abs(Sum([ResidentCount]/27 >=.9)) as DaysFilled
FROM YourTable
WHERE [Date] Between #2006-1-1# and #2007-12-31#
GROUP BY Format([Date],"yyyy-mm")
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
AccessNeophyte wrote:
Hi All,
I'v browsed this group for an answer to this, with no success.
This is my situation:
I need to end up with the number of days during a given month on
which
the total number of residents ("Occupancy") meets or exceeds 90% of
our Capacity of 27.
I've done this with an Excel spreadsheet, summing these columns:
Col A Col B Col C Col D
Date ~ # of residents ~ % of Capacity ~ 0 or 1, depending
="Col B"/27 ~ =IF("Col C"
0.9,1,0)
Is there an expression(s) that will give me the total from Col D?
Thanks,
Liz- Hide quoted text -
- Show quoted text -
Thanks John - I always enjoy your posts.
You give me credit for being farther along in my understanding of
Access than I am. Is it possible to get this information in the
format of what expressions I would use in a query, in Query Design
view, rather than SQL view?
Would it help if I were to send the spreadsheet I currently use? I
don't know If I was clear about what the columns contained.
Column A contains each day of the month in question.
Column B contains (I believe) what you have called [ResidentCount] for
each date.
If it helps, the fields from my table that I'm trying to use in my
query are:
BMC_ID (pk)
AdmitDate
DischargeDate
Thanks,
Liz- Hide quoted text -
- Show quoted text -
SO the first question is have you already calculated the number of
people in the facility for each day.
Liz - No
Or are you planning to calculate them using the AdmitDate and
Discharge Date?
Liz - Hoping to, yes.
If so, do you have a table of dates in your database?
Liz - Unclear what you mean by "table of dates." I have fields in my
"Client Data" table for AdmitDate & DischargeDate. I don't think
that's what you mean, though.- Hide quoted text -
- Show quoted text -

Thanks John,

Is there a simple way to enter all the dates from 1/1/2007 forward
into this table? I can't find anything helpful in Help or in
microsoft.public.access.tabledesign.

Liz- Hide quoted text -

- Show quoted text -

Update!!

Here is the SQL for qBase:
SELECT Count([BMC Client Data Table].BMC_ID) AS CountOfBMC_ID,
tDates2.fDate
FROM [BMC Client Data Table], tDates2
WHERE (((tDates2.fDate) Between [BMC Client Data Table]![AdmitDate]
And [BMC Client Data Table]![DC_DischargeDate]))
GROUP BY tDates2.fDate;

Here is the SQL for the second query, which I called qBase2:
SELECT Count(qBase.fDate) AS CountOffDate, Format(qBase.fDate,"yyyy-
mm") AS Expr1
FROM qBase
WHERE (((qBase.CountOfBMC_ID)>0.9*27))
GROUP BY Format(qBase.fDate,"yyyy-mm");

Is this correct?

BTW, for the dates table, I just did an autofill in Excel (all 65536
lines!) and imported it. That gave me dates through 6/6/2186. That
ought to hold us for a while. ;o}

I have another query I set up to show me the Total Occupancy on a
given date ([Requested Date] in the query). This is what I was hoping
I would NOT have to run for each day of the month in order to get my
final total. When I run that query for several days of my test month,
some of the totals I get are different from the results of qBase.

This is the SQL for that query:
SELECT [BMC Client Data Table].BMC_ID, [BMC Client Data Table].Bed,
[BMC Client Data Table].AdmitDate, [BMC Client Data Table].Gender,
[BMC Client Data Table].LastName, [Requested Date] AS Expr1, [BMC
Client Data Table].DC_DischargeDate, [BMC Client Data
Table].FirstName, Now() AS Expr2
FROM [BMC Client Data Table]
WHERE ((([BMC Client Data Table].AdmitDate)<=[Requested Date]) AND
(([BMC Client Data Table].DC_DischargeDate) Is Null)) OR ((([BMC
Client Data Table].AdmitDate)<=[Requested Date]) AND (([BMC Client
Data Table].DC_DischargeDate)>[Requested Date]))
ORDER BY [BMC Client Data Table].Bed, [BMC Client Data
Table].AdmitDate, [BMC Client Data Table].Gender, [BMC Client Data
Table].LastName;

Any idea why I'm getting different numbers?

Thanks,
Liz
 
M

Michael Gramelspacher

might work, if I ddid not messed up table & column names:

SELECT COUNT(* ) AS [Days Exceeding 90%],
FORMAT([fDate],"yyyy-mm") AS [Year-Month]
FROM (SELECT c.fDate,
COUNT(b.bmc_id) AS [Daily Count]
FROM tDates2 AS c
LEFT JOIN [BMC Client Data Table] AS b
ON (c.fDate < NZ(b.DC_DischargeDate,DATEADD('d',1,[End date:])))
AND (c.fDate >= b.AdmitDate)
WHERE c.fDate BETWEEN [Start date:]
AND [End date:]
GROUP BY c.fDate) AS a
WHERE ((([Daily Count]) > 0.9 * 27))
GROUP BY FORMAT([fDate],"yyyy-mm");
 
M

Maelinar

A query can give you your total.

Organise your query along these lines:

Field [ReferenceID]
Table [name]
Total: Count
Show: Yes

Field [Col D]
Table [name]
Show: No
Criteria: ="1"

The result of your query will give you a single cell (crazy excel term)
tally of all fields that contain a 1 in your Col D field.

Maelinar
 
A

AccessNeophyte

might work, if I ddid not messed up table & column names:

SELECT COUNT(* ) AS [Days Exceeding 90%],
FORMAT([fDate],"yyyy-mm") AS [Year-Month]
FROM (SELECT c.fDate,
COUNT(b.bmc_id) AS [Daily Count]
FROM tDates2 AS c
LEFT JOIN [BMC Client Data Table] AS b
ON (c.fDate < NZ(b.DC_DischargeDate,DATEADD('d',1,[End date:])))
AND (c.fDate >= b.AdmitDate)
WHERE c.fDate BETWEEN [Start date:]
AND [End date:]
GROUP BY c.fDate) AS a
WHERE ((([Daily Count]) > 0.9 * 27))
GROUP BY FORMAT([fDate],"yyyy-mm");- Hide quoted text -

- Show quoted text -

Hi Michael,

I've been playing with this, going back and forth between SQL view &
Design view. I'm learning a lot about SQL by doing this, so many
thanks!

Let me see if I've got this right:
In this segment, FROM (SELECT c.fDate,
"c" is the table tDate that has the field fDate, meaning that it would
say:
FROM (SELECT [tDate].[fDate]

Am I on the right track?
Liz
 
M

Michael Gramelspacher

Yes, c is just an alias for tDate. Without aliases queries just become too
verbose and confusing to make sense of. In query design view you can right
click any table and select properties and give it an alias, but all queries
cannot be displayed in design view. The table subquery (derived query)that is
used in place of table name itself has an alias. By the way that table subquery
could instead be a separate query. Then the query name would be substited for
it. Example:

Query: Daily Count Query
-------------------------
SELECT c.fDate,
COUNT(b.bmc_id) AS [Daily Count]
FROM tDates2 AS c
LEFT JOIN [BMC Client Data Table] AS b
ON (c.fDate < NZ(b.DC_DischargeDate,DATEADD('d',1,[End date:])))
AND (c.fDate >= b.AdmitDate)
WHERE c.fDate BETWEEN [Start date:]
AND [End date:]
GROUP BY c.fDate

Query: Days Exceeding Threshold
--------------------------------
SELECT COUNT(* ) AS [Days Exceeding 90%],
FORMAT([fDate],"yyyy-mm") AS [Year-Month]
FROM [Daily Count Query]
WHERE ((([Daily Count]) > 0.9 * 27))
GROUP BY FORMAT([fDate],"yyyy-mm");
 

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