Glenda:
Yes, you can do it with an aggregate function in a control in the report,
but it needs a little mild trickery. To conditionally count rows depending
on the value of a field you do it by summing the values of an expression
which returns 1 or 0 depending on the value. The expression calls the IIf
function to return a 1 or 0 and then the Sum function to (not surprisingly)
sum them. Summing all the 1 and 0 values in effect counts all the 1s. So in
the group footer of your report put 3 text boxes side by side with the
following ControlSources:
=Sum(IIf([Status] = "OK",1,0))
=Sum(IIf([Status] = "R",1,0))
=Sum(IIf([Status] = "NCR",1,0))
This should give you the counts of each value in the group.
You will sometimes see recommendations to do it another way:
=Sum(Abs([Status] = "OK"))
or:
=Sum(([Status] = "OK")*-1)
This relies on the fact that in Access True is implemented as -1 and False
as 0, so by summing the absolute values of these (or the value * -1) you are
again summing all the 1s and 0s. Don't do it this way! It will work but its
bad programming practice to rely on the implementation in this way; its what
the head of a software company of my acquaintance once called "being unduly
chummy with the implementation".
Ken Sheridan
Stafford,
Glenda said:
I know very little about Access. Where would I put all of the suggested "Try
this" below? Is there a way to just insert a text box with something similar
to "Avg([xx])"?
--
Glenda
KARL DEWEY said:
Try this --
TRANSFORM Count(Your_Table.Status) AS CountOfStatus
SELECT Your_Table.Model
FROM Your_Table
GROUP BY Your_Table.Model
PIVOT Your_Table.Status;
:
I have a field titled "Status". The status can be "ok", "R", "NCR", etc.
I would like to display columns in the summary report that have the quantity
of records (in that group) that have a status of "ok", "R", etc. I've set up
the report with the grouping by the model. I don't understand the DCOUNT
function. Please help.
e.g.
Model OK R NCR
A 1 2 43
B 33 39 44