質問

This should be simple. I cam do it easily in Excel, but it isn't making the jump. I have a database tracking the status of a fleet of trucks, including various scheduled maintenance services. I have a query that polls all the services (quarterly, semi-annual, annual), and lists the tolerance due dates for the service. Then I have a report, where I want to include some basic totals: How many of each kind of vehicle is in the shop, how many are due for each kind of service.

The trouble comes from counting the status. "In shop" could be 10%, 50%, 90% complete. So I'm trying to get a count() formula to use a wildcard. This one doesn't work:

=Count(IIf([Status] = "In Shop*",1,0))

That asterisk gets me every item in the field, blanks or no.

役に立ちましたか?

解決

How about this (EDIT: I believe you actually want to use the SUM function here, not COUNT):

=Sum(IIf(Left([Status], 7) = "In Shop", 1, 0)

他のヒント

The issue is that you aren't grouping by another field, so Count() is going to return all items.

Three ways to resolve this off the top of my head:

  1. Create a separate field where you perform the IIF statement. Then, perform the Count() against that field but include that field in your GroupBy clause.
  2. Create a VBA function to encapsulate this logic and invoke the function from the control on the report.
  3. Instead of using Count() use Sum.

Example:

Sum(IIf([Status] Like "in shop*",1,0))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top