calculated field

L

Lesa Havert

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
J

John W. Vinson

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.

Please post the complete SQL view of the query.
 
L

Lesa Havert

Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
K

KARL DEWEY

You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
L

Lesa Havert

Thanks for your response, John. Below is the complete SQL view of the query
(transposed from Access for clarity). No sort order or "Criteria" filters
were used. Hope it helps.

************************************************************
QA los (3) : Select Query

Table (partial):

OSHPD PDD NP 2006
*
oshpd_id
typecare
agdyadm
agyradm

Query:

Fields: Table Total Show
1st: oshpd_id OSHPD PDD NP 2006 X

2nd: oshpd_id OSHPD PDD NP 2006 X

3rd: LOStotal: IIf([OSHPD PDD NP 2006]!los=0,Count([OSHPD PDD NP
2006]!los),Sum([OSHPD PDD NP 2006]!los)) X

4th: los OSHPD PDD NP 2006 X

5th: los OSHPD PDD NP 2006 X

************************************************************


--
Lesa Havert
Market Research
UC Davis Health System


John W. Vinson said:
definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.

Please post the complete SQL view of the query.
 
L

Lesa Havert

Thanks much, Karl. I will try it. I just posted the SQL view of the query
to John - hope it helps.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


:

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
K

KARL DEWEY

What you posted for John is not the SQL.
Open the query in design view, click on menu VIEW - SQL View, highlight all,
copy, and paste in a post.
It should look something like this --
SELECT oshpd_id, typecare, agdyadm, agyradm, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY oshpd_id, typecare, agdyadm, agyradm;

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks much, Karl. I will try it. I just posted the SQL view of the query
to John - hope it helps.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


:

Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


:

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
L

Lesa Havert

Hi Karl/John:

Below is the SQL view of my latest query (based on John's suggested formula
in the previous email) - LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD
PDD NP 2006]![los]) - in which the formula syntax didn't work (incorrect or
incomplete). Unfortunately, the query I ran with the formula below didn't
count the "0" los days.

SELECT [OSHPD PDD NP 2006].oshpd_id, Count([OSHPD PDD NP 2006].oshpd_id) AS
CountOfoshpd_id, Sum(IIf([OSHPD PDD NP 2006]![los]=0,[OSHPD PDD NP
2006]![los]=1,[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id;

I am continually working on it from my end, and greatly appreciate any
assistance you can give with this area of Access that is relatively
unfamiliar to me.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
What you posted for John is not the SQL.
Open the query in design view, click on menu VIEW - SQL View, highlight all,
copy, and paste in a post.
It should look something like this --
SELECT oshpd_id, typecare, agdyadm, agyradm, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY oshpd_id, typecare, agdyadm, agyradm;

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks much, Karl. I will try it. I just posted the SQL view of the query
to John - hope it helps.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


:

Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


:

Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


:

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
K

KARL DEWEY

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
There is a comma omitted following the =0,1 so it should read --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1,[OSHPD PDD NP 2006]![los])

One mo' time --
SELECT [OSHPD PDD NP 2006].oshpd_id, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1,[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id;

I just tested using this data --
oshpd_id Los
1 0
1 2
1 3
1 0
1 5
1 0
1 0
2 0
2 1
2 4
2 0
This results --
oshpd_id LOStotal
1 14
2 7
--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Hi Karl/John:

Below is the SQL view of my latest query (based on John's suggested formula
in the previous email) - LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD
PDD NP 2006]![los]) - in which the formula syntax didn't work (incorrect or
incomplete). Unfortunately, the query I ran with the formula below didn't
count the "0" los days.

SELECT [OSHPD PDD NP 2006].oshpd_id, Count([OSHPD PDD NP 2006].oshpd_id) AS
CountOfoshpd_id, Sum(IIf([OSHPD PDD NP 2006]![los]=0,[OSHPD PDD NP
2006]![los]=1,[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id;

I am continually working on it from my end, and greatly appreciate any
assistance you can give with this area of Access that is relatively
unfamiliar to me.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
What you posted for John is not the SQL.
Open the query in design view, click on menu VIEW - SQL View, highlight all,
copy, and paste in a post.
It should look something like this --
SELECT oshpd_id, typecare, agdyadm, agyradm, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY oshpd_id, typecare, agdyadm, agyradm;

--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Thanks much, Karl. I will try it. I just posted the SQL view of the query
to John - hope it helps.

--
Lesa Havert
Market Research
UC Davis Health System


:

You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


:

Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


:

Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


:

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 
L

Lesa Havert

John:

Below is the SQL view of a query that captured "los" = 0 days. It is based
on query (rather than table) fields. Unfortunately, it produces too many
rows, which is why I was trying to write the formula for the calculated field
from the table. (Thanks again for any suggestions you can provide.)

SELECT [OSHPD PDD NP 2006].oshpd_id, Count([OSHPD PDD NP 2006].oshpd_id) AS
CountOfoshpd_id, [OSHPD PDD NP 2006].los,
IIf([los]=0,[CountOflos],[SumOflos]) AS Expr1, Count([OSHPD PDD NP 2006].los)
AS CountOflos, Sum([OSHPD PDD NP 2006].los) AS SumOflos
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id, [OSHPD PDD NP 2006].los,
IIf([los]=0,[CountOflos],[SumOflos]);


--
Lesa Havert
Market Research
UC Davis Health System


John W. Vinson said:
definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.

Please post the complete SQL view of the query.
 
L

Lesa Havert

The formula worked! Thank you so much Karl...


--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
There is a comma omitted following the =0,1 so it should read --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1,[OSHPD PDD NP 2006]![los])

One mo' time --
SELECT [OSHPD PDD NP 2006].oshpd_id, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1,[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id;

I just tested using this data --
oshpd_id Los
1 0
1 2
1 3
1 0
1 5
1 0
1 0
2 0
2 1
2 4
2 0
This results --
oshpd_id LOStotal
1 14
2 7
--
KARL DEWEY
Build a little - Test a little


Lesa Havert said:
Hi Karl/John:

Below is the SQL view of my latest query (based on John's suggested formula
in the previous email) - LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD
PDD NP 2006]![los]) - in which the formula syntax didn't work (incorrect or
incomplete). Unfortunately, the query I ran with the formula below didn't
count the "0" los days.

SELECT [OSHPD PDD NP 2006].oshpd_id, Count([OSHPD PDD NP 2006].oshpd_id) AS
CountOfoshpd_id, Sum(IIf([OSHPD PDD NP 2006]![los]=0,[OSHPD PDD NP
2006]![los]=1,[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY [OSHPD PDD NP 2006].oshpd_id;

I am continually working on it from my end, and greatly appreciate any
assistance you can give with this area of Access that is relatively
unfamiliar to me.

--
Lesa Havert
Market Research
UC Davis Health System


KARL DEWEY said:
What you posted for John is not the SQL.
Open the query in design view, click on menu VIEW - SQL View, highlight all,
copy, and paste in a post.
It should look something like this --
SELECT oshpd_id, typecare, agdyadm, agyradm, Sum(IIf([OSHPD PDD NP
2006]![los]=0,1[OSHPD PDD NP 2006]![los])) AS LOStotal
FROM [OSHPD PDD NP 2006]
GROUP BY oshpd_id, typecare, agdyadm, agyradm;

--
KARL DEWEY
Build a little - Test a little


:

Thanks much, Karl. I will try it. I just posted the SQL view of the query
to John - hope it helps.

--
Lesa Havert
Market Research
UC Davis Health System


:

You did not post your SQL as requested by John Vinson but try this --
LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,1[OSHPD PDD NP 2006]![los])
This test if Los is zero, substitutes 1. Put this in your totals query and
change the Group By to Sum.

--
KARL DEWEY
Build a little - Test a little


:

Thanks for your response, Karl. The patient discharge database I manage
(which is purchased annually each calendar year) is huge, with ~125 fields
and almost 3 million records. Below is a summary:

Field Name Data Type Description
oshpd_id Text Hospital I.D. number (assigned by OSHPD)
typcare Text type of care (e.g., acute, rehabilitation, psych/chem dep,
skilled nursing)
agdyadm Number age in days
agyradm Number age in years
sex Text gender (male, female, unknown, blank)
ethncty Text ethnicity (Hispanic vs non-Hispanic)
race Text race (White, African American, Asian/Pacific Islander, American
Indian, etc.)
patzip Text patient zip code
patcnty Text patient county of residence
los Number length of stay (in days); if length of stay < 24 hours, recorded
as "0" length of stay
admtday Text day of admission
admtmth Text month of admission
admtyr Text year of admission
srcsite Text source of admission (e.g., home, residential care or skilled
nursing facility, ambulatory surgery center, etc.)
srclicns Text licensure of site (this hospital, another hospital, not a
hospital)
srcroute Text route of admission (emergency room vs other)
admtype Text type of admission (scheduled, unscheduled, infant, unknown)
disp Text disposition of patient (where patient released - e.g., home, care
facility, etc.)
pay_cat Text payor category code (Medicare, Medi-Cal, Private, Worker's
Comp, Other Government, County Indigent, Self-Pay, etc.)
pay_type Text payor type code (managed care, other)
pay_plan Text payor plan code (health plan licensed under Knox Keene - e.g.,
Kaiser)
charge Currency total charges for services rendered
ecode_p Text primary e-code (external cause of injury) (ICD-9 code manual)
ecodes1-4 Text other e-codes (ICD-9 code manual)
mdc Text major diagnostic category (25 categories containing all possible
principal diagnosis areas)
drg Text diagnosis-related groups (hospital patient groupings to categories
based on diagnostic, therapeutic & demographic characteristics for the
purpose of reimbursement)
diag_p Text principal diagnosis code (chief cause of patient's admission)
cpoa_p Text condition present on admission
proc_p Text principal procedure (procedure performed for definitive treatment)
proc_pdy Number number of patient days from admission to performance of
procedure
odiag1-24 Text other diagnosis codes (condition that exists at the time of
admission)
cpoa1-24 Text whether condition was present on admission (yes, no, uncertain)
oproc1-20 Text days from admission to other procedure
procdy1-20 Number other procedure codes reported according to the ICD-9 code
manual
hplzip Text hospital zip code
hplcnty Text hospital county code
mth_dsch Text month the patient was discharged from the hospital


The problem I am trying to solve using a calculated field is for the numeric
field "los" (length of patient stay in days). If a patient stays less than
24 hours, it is recorded as "0" in the primary (linked) table of the
database, but for our market research purposes, it should be "1." In my
current database (2006), there are a total of 20,637,531 patient days (los),
95,490 of which had a "0" los. I can capture all patient days on a given
query if I perform a "count" of los=0 and "sum" of los>=1.

I hope this makes sense. And thanks for any help you can provide.

--
Lesa Havert
Market Research
UC Davis Health System


:

Post your table structure with field names and datatype along with sample data.
--
KARL DEWEY
Build a little - Test a little


:

definition in formula: LOS = length of stay (number of days - numeric field)

When using the below expression in a calculated field, I get an error
message stating that I tried to execute a query that does not include the
expression as part of an aggregate function.

LOStotal: IIf([OSHPD PDD NP 2006]![los]=0,Count([OSHPD PDD NP
2006]![los]),Sum([OSHPD PDD NP 2006]![los]))

I pulled the bracket detail from my base database table and the functions
from the "built-in functions" list. I used the "expression" category in the
"total" field. I successfully execute the query when configuring the formula
from the query (rather than table) fields, but want to use the table fields
if possible.

Any suggestions you can provide would be much appreciated. Thanks.
 

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