DCount function for filtered data in table

K

Kaylen

Now I am thinking with all the experts in here, I am wondering if anyone can
help me with a formula that can calculate just the selective range of data of
a certain date. Based on initial problem I stated below, I have to make a
query that filter out only records of a certain date, then from that query I
use the IIf function to calculate the count of Y over the count of Y+N. Is
there a way or expression where I can eliminate having to create that query
and just calculated the percentage of (Y/Y+N) of all the records of a
selected date filtered from the table UM? Keep in mind that I still would
like the value to be "N/A" if there is no Y or N in the field of the selected
date. Any suggestion for the problem would be very much appreciated.


Let me explain the problem clearer. I have a table with fields headings in
numbers. The data in the fields is Y, N, or N/A. I want to calculate the
percentage of the count of Y over the count of Y and N, exclude N/A in the
denominator. But first I needed to filter out a certain selection in the
table only. That is why I made a query called "UM"( to filter out records
entered on certain date only). Now I want to calculate the number of Y/(N+Y)
based on data filtered by the query. I learned that you can't calculate if
the query has a parameter, or could you? The formula I use to calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount(" [UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A", neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the case instead of
returning an error message. Please please help......
 
J

John Spencer

Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only give you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01# and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word WHERE
for the third argument of the DCount.

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

Kaylen said:
Now I am thinking with all the experts in here, I am wondering if anyone
can
help me with a formula that can calculate just the selective range of data
of
a certain date. Based on initial problem I stated below, I have to make a
query that filter out only records of a certain date, then from that query
I
use the IIf function to calculate the count of Y over the count of Y+N. Is
there a way or expression where I can eliminate having to create that
query
and just calculated the percentage of (Y/Y+N) of all the records of a
selected date filtered from the table UM? Keep in mind that I still would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.


Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to calculate
the
percentage of the count of Y over the count of Y and N, exclude N/A
in the
denominator. But first I needed to filter out a certain selection in
the
table only. That is why I made a query called "UM"( to filter out
records
entered on certain date only). Now I want to calculate the number of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the case
instead of
returning an error message. Please please help......
 
K

Kaylen

I am soo glad that the answer is YES. But I would need more specific help.
Here is the master formula that I use in the query field that filtered out a
specific date.

=IIf(DCount("*","UM","[13] IN
('Y','N')")=0,"N/A",FormatPercent((DCount("*","UM","[13]
='Y'")/DCount("*","UM","[13] IN ('Y','N')")),0))

How can I use this formula to direct Access to filter out the date for
example 9/9/09 in the TABLE "UM Files". [13] is a field with Y, N, and N/A.
Please help. I only have this one day to figure it out if I can. Thank u....

John Spencer said:
Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only give you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01# and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word WHERE
for the third argument of the DCount.

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

Kaylen said:
Now I am thinking with all the experts in here, I am wondering if anyone
can
help me with a formula that can calculate just the selective range of data
of
a certain date. Based on initial problem I stated below, I have to make a
query that filter out only records of a certain date, then from that query
I
use the IIf function to calculate the count of Y over the count of Y+N. Is
there a way or expression where I can eliminate having to create that
query
and just calculated the percentage of (Y/Y+N) of all the records of a
selected date filtered from the table UM? Keep in mind that I still would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.


Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to calculate
the
percentage of the count of Y over the count of Y and N, exclude N/A
in the
denominator. But first I needed to filter out a certain selection in
the
table only. That is why I made a query called "UM"( to filter out
records
entered on certain date only). Now I want to calculate the number of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the case
instead of
returning an error message. Please please help......
 
J

John Spencer

WHAT is the NAME of the DateField?

IIf(DCount("*","UM","[13] IN ('Y','N') AND [NameOfDateField] =
#9/9/09#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [NameOfDateField]=
#9/9/09#")/
DCount("*","UM","[13] IN ('Y','N') and [NameOfDateField]=#9/9/09#")),0))

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

Kaylen said:
I am soo glad that the answer is YES. But I would need more specific help.
Here is the master formula that I use in the query field that filtered out
a
specific date.

=IIf(DCount("*","UM","[13] IN
('Y','N')")=0,"N/A",FormatPercent((DCount("*","UM","[13]
='Y'")/DCount("*","UM","[13] IN ('Y','N')")),0))

How can I use this formula to direct Access to filter out the date for
example 9/9/09 in the TABLE "UM Files". [13] is a field with Y, N, and
N/A.
Please help. I only have this one day to figure it out if I can. Thank
u....

John Spencer said:
Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only give
you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01# and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word WHERE
for the third argument of the DCount.

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

Kaylen said:
Now I am thinking with all the experts in here, I am wondering if
anyone
can
help me with a formula that can calculate just the selective range of
data
of
a certain date. Based on initial problem I stated below, I have to make
a
query that filter out only records of a certain date, then from that
query
I
use the IIf function to calculate the count of Y over the count of Y+N.
Is
there a way or expression where I can eliminate having to create that
query
and just calculated the percentage of (Y/Y+N) of all the records of a
selected date filtered from the table UM? Keep in mind that I still
would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.



Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to
calculate
the
percentage of the count of Y over the count of Y and N, exclude
N/A
in the
denominator. But first I needed to filter out a certain selection
in
the
table only. That is why I made a query called "UM"( to filter out
records
entered on certain date only). Now I want to calculate the number
of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the case
instead of
returning an error message. Please please help......
 
K

Kaylen

The name of the data field is [Review Date]. 9/9/09 is just an example of the
date, is there a forumla that prompt the user to enter in the review date
themselves everytime they run the calculated query? I dont want them to mess
with the formual. Like # reviewdate# in the formula so they can just enter
the desired date.

John Spencer said:
WHAT is the NAME of the DateField?

IIf(DCount("*","UM","[13] IN ('Y','N') AND [NameOfDateField] =
#9/9/09#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [NameOfDateField]=
#9/9/09#")/
DCount("*","UM","[13] IN ('Y','N') and [NameOfDateField]=#9/9/09#")),0))

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

Kaylen said:
I am soo glad that the answer is YES. But I would need more specific help.
Here is the master formula that I use in the query field that filtered out
a
specific date.

=IIf(DCount("*","UM","[13] IN
('Y','N')")=0,"N/A",FormatPercent((DCount("*","UM","[13]
='Y'")/DCount("*","UM","[13] IN ('Y','N')")),0))

How can I use this formula to direct Access to filter out the date for
example 9/9/09 in the TABLE "UM Files". [13] is a field with Y, N, and
N/A.
Please help. I only have this one day to figure it out if I can. Thank
u....

John Spencer said:
Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only give
you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01# and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word WHERE
for the third argument of the DCount.

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

Now I am thinking with all the experts in here, I am wondering if
anyone
can
help me with a formula that can calculate just the selective range of
data
of
a certain date. Based on initial problem I stated below, I have to make
a
query that filter out only records of a certain date, then from that
query
I
use the IIf function to calculate the count of Y over the count of Y+N.
Is
there a way or expression where I can eliminate having to create that
query
and just calculated the percentage of (Y/Y+N) of all the records of a
selected date filtered from the table UM? Keep in mind that I still
would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.



Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to
calculate
the
percentage of the count of Y over the count of Y and N, exclude
N/A
in the
denominator. But first I needed to filter out a certain selection
in
the
table only. That is why I made a query called "UM"( to filter out
records
entered on certain date only). Now I want to calculate the number
of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the case
instead of
returning an error message. Please please help......
 
J

John Spencer

No guesses on whether all the parentheses are correctly matched, but you can
try something like

IIf(DCount("*","UM","[13] IN ('Y','N')
AND [Review Date] =#" & [Enter Date] & "#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [Review Date]=#" &
[Enter Date] & "#")/
DCount("*","UM","[13] IN ('Y','N') and [Review Date=#" & [Enter Date] &
"#")),0))

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

Kaylen said:
The name of the data field is [Review Date]. 9/9/09 is just an example of
the
date, is there a forumla that prompt the user to enter in the review date
themselves everytime they run the calculated query? I dont want them to
mess
with the formual. Like # reviewdate# in the formula so they can just enter
the desired date.

John Spencer said:
WHAT is the NAME of the DateField?

IIf(DCount("*","UM","[13] IN ('Y','N') AND [NameOfDateField] =
#9/9/09#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [NameOfDateField]=
#9/9/09#")/
DCount("*","UM","[13] IN ('Y','N') and [NameOfDateField]=#9/9/09#")),0))

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

Kaylen said:
I am soo glad that the answer is YES. But I would need more specific
help.
Here is the master formula that I use in the query field that filtered
out
a
specific date.

=IIf(DCount("*","UM","[13] IN
('Y','N')")=0,"N/A",FormatPercent((DCount("*","UM","[13]
='Y'")/DCount("*","UM","[13] IN ('Y','N')")),0))

How can I use this formula to direct Access to filter out the date for
example 9/9/09 in the TABLE "UM Files". [13] is a field with Y, N,
and
N/A.
Please help. I only have this one day to figure it out if I can. Thank
u....

:

Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only
give
you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01#
and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word
WHERE
for the third argument of the DCount.

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

Now I am thinking with all the experts in here, I am wondering if
anyone
can
help me with a formula that can calculate just the selective range
of
data
of
a certain date. Based on initial problem I stated below, I have to
make
a
query that filter out only records of a certain date, then from that
query
I
use the IIf function to calculate the count of Y over the count of
Y+N.
Is
there a way or expression where I can eliminate having to create
that
query
and just calculated the percentage of (Y/Y+N) of all the records of
a
selected date filtered from the table UM? Keep in mind that I still
would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.



Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to
calculate
the
percentage of the count of Y over the count of Y and N, exclude
N/A
in the
denominator. But first I needed to filter out a certain
selection
in
the
table only. That is why I made a query called "UM"( to filter
out
records
entered on certain date only). Now I want to calculate the
number
of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the
case
instead of
returning an error message. Please please help......
 
K

Kaylen

I edit the formula you gave me to this:

=IIf(DCount("*","UM Files","[13] IN ('Y','N')
AND [Review Date] =#" & [Enter Date] &
"#")=0,"N/A",FormatPercent((DCount("*","UM Files","[13] ='Y' and [Review
Date]=#" & [Enter Date] & "#")/DCount("*","UM Files","[13] IN ('Y','N') and
[Review Date=#" & [Enter Date] & "#")),0))

I put this formula in a query but I got an error message:

Missing ), ], or Item in query expression '[13] IN ('Y','N') and [Review
Date=#9/9/09#'.

then I got this error message:

This expression is typed incorrectly, or it is too complex to be evaluated.
For example, a numeric expression may contain too many complicated elements.
Try simplifying the expression by assigning parts of the expression to
variables. (Error 3071)

John Spencer said:
No guesses on whether all the parentheses are correctly matched, but you can
try something like

IIf(DCount("*","UM","[13] IN ('Y','N')
AND [Review Date] =#" & [Enter Date] & "#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [Review Date]=#" &
[Enter Date] & "#")/
DCount("*","UM","[13] IN ('Y','N') and [Review Date=#" & [Enter Date] &
"#")),0))

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

Kaylen said:
The name of the data field is [Review Date]. 9/9/09 is just an example of
the
date, is there a forumla that prompt the user to enter in the review date
themselves everytime they run the calculated query? I dont want them to
mess
with the formual. Like # reviewdate# in the formula so they can just enter
the desired date.

John Spencer said:
WHAT is the NAME of the DateField?

IIf(DCount("*","UM","[13] IN ('Y','N') AND [NameOfDateField] =
#9/9/09#")=0,
"N/A",FormatPercent((DCount("*","UM","[13] ='Y' and [NameOfDateField]=
#9/9/09#")/
DCount("*","UM","[13] IN ('Y','N') and [NameOfDateField]=#9/9/09#")),0))

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

I am soo glad that the answer is YES. But I would need more specific
help.
Here is the master formula that I use in the query field that filtered
out
a
specific date.

=IIf(DCount("*","UM","[13] IN
('Y','N')")=0,"N/A",FormatPercent((DCount("*","UM","[13]
='Y'")/DCount("*","UM","[13] IN ('Y','N')")),0))

How can I use this formula to direct Access to filter out the date for
example 9/9/09 in the TABLE "UM Files". [13] is a field with Y, N,
and
N/A.
Please help. I only have this one day to figure it out if I can. Thank
u....

:

Yes, you could add additional criteria to the where argument of the
expression. Since I have no idea of the date field name I can only
give
you
a generic idea.

DCount("*","UM","[13] ='Y' AND [SomeDateField] Between #2008-01-01#
and
#2008-01-31#")

Basically, you need to construct a WHERE statement without the word
WHERE
for the third argument of the DCount.

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

Now I am thinking with all the experts in here, I am wondering if
anyone
can
help me with a formula that can calculate just the selective range
of
data
of
a certain date. Based on initial problem I stated below, I have to
make
a
query that filter out only records of a certain date, then from that
query
I
use the IIf function to calculate the count of Y over the count of
Y+N.
Is
there a way or expression where I can eliminate having to create
that
query
and just calculated the percentage of (Y/Y+N) of all the records of
a
selected date filtered from the table UM? Keep in mind that I still
would
like the value to be "N/A" if there is no Y or N in the field of the
selected
date. Any suggestion for the problem would be very much appreciated.



Let me explain the problem clearer. I have a table with fields
headings in
numbers. The data in the fields is Y, N, or N/A. I want to
calculate
the
percentage of the count of Y over the count of Y and N, exclude
N/A
in the
denominator. But first I needed to filter out a certain
selection
in
the
table only. That is why I made a query called "UM"( to filter
out
records
entered on certain date only). Now I want to calculate the
number
of
Y/(N+Y)
based on data filtered by the query. I learned that you can't
calculate if
the query has a parameter, or could you? The formula I use to
calulate the Y
and N of field 13 in the query UM is

=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))

which works fine until all the data is if that field is "N/A",
neither "Y'
or "N". Now I need a fomula that returns "N/A" if this is the
case
instead of
returning an error message. Please please help......
 
J

John Spencer

WHERE are you trying to use the expression. The equals sign in front
of the expression leads me to believe that you are NOT doing this in a
query, but are attempting to use the expression elsewhere.

If you are trying use this as a control source for a control on a form
or report, then you need to have the date available from some source
(perhaps a control on a form where you manually enter a date or in a query).

You can try testing this a step at a time.

For instance, you could test with something like the following sequence.
Every time the expression blows up, fix that portion and then continue
on to the next part.


=IIf(DCount("*","UM Files",
"[13] IN ('Y','N')AND [Review Date] =#" &
Forms![FormName]![TargetDateControl] & "#")=0,"Is Zero","Is not Zero")

If that work you know the first section is ok. If not, play with it
until you get the desired result. Then add the section you need to show
the results you want. Again you might do this bit by bit.

=IIf(DCount("*","UM Files",
"[13] IN ('Y','N') AND [Review Date] =#" &
Forms![FormName]![TargetDateControl] & "#")=0,

"N/A",

DCount("*","UM Files",
"[13] ='Y' and [Review Date]=#" & Forms![FormName]![TargetDateControl]
& "#"))

If that works add the next portion - the divisor.

If that works add in the FormatPercent call.


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

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