I tried the formula, it returns a 0% when all the data is "N/A" but it was
incorrect when the data is not "N/A". 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 insteadof
returning an error message. Please please help......
BruceM said:
If there is neither Y nor N, the divisor is 0, which is why you are getting
the error. You can simplify the DCount syntax, and allow for a zero for the
N count:
=IIf(DCount("*","[UM]","[13] = 'N/A'") =
DCount("*","[UM]"),0,DCount("*","[UM]","[13] = 'Y'")/DCount("*","[UM]","[13]
= 'Y'") + DCount("*","[UM]","[13] = 'N'"))
That is, if the number of records with "N/A" equals the total number of
records, return a 0, otherwise go ahead with the calculation.
Kaylen said:
First I want to let you know how much I appreciate your effort to help..
Sorry
I am quite new to Access 2003 so your help in details would be very
helpful
to me. I tried what you suggest but it still wouldn't work. I want to use
this formula to calculate the percentage:
=DCount("[UM]![13]","UM","[UM]![13]='Y'")/(DCount("
[UM]![13]","UM","[UM]![13]='Y'")+DCount("
[UM]![13]","UM","[UM]![13]='N'"))
meaning the count of Y in UM query field 13/ (count of Y+N in UM query
field
13)
This formula works but when field 13 has all "N/A" and not a Y or N, there
is an error message of #Num!. I want the formula to return a "N/A" if that
is
the case instead of #Num! So do you think I should use the IIf function?
if
so, what will it be? Please help....
:
I tried to answer your other question but obviously you haven't read it.
Go
to tools-->macros-->Visual Basic Editor
Click on View then click on Immediate Window
In that window type in
?DCount("[UM]![5]","UM","[UM]![5]='Y'")
Don't forget the question mark
Play around with that til you get it to accurately count that table.
You are completely all over the place with this. And read your other
posts.
:
I really need help on this. I want a field in a query to calculate the
pecentage of the count "Y" over the sum of "Y" and "N". The formulais
use
for this is:
=DCount("[UM]![5]","UM","[UM]![5]='Y'")/(DCount("
[UM]![5]","UM","[UM]![5]='Y'")+DCount(" [UM]![5]","UM","[UM]![5]='N'"))
But when all my data for that column is "N/A", I get the error message
in
the query:
"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 expressionto
variables." when I run the query.
If I try to put that same formula into a control source of a text box,
I get
the return value of #NUM!. I guess I want the formula to works but if
none
the data in the feild is a "Y" or "N"" then I want it to return "N/A"
instead
of error messages. Any advice on this problem quick is very much
appreciated.- Hide quoted text -
- Show quoted text -