View Full Version : Count If Type = ?


cbayardo
04-22-2004, 03:50 PM
Hi,
I am making a report and I am doing a count of the records, but I also want to do a count if a the Field Type is equal to a number. For example:

Name Type1 Price1 Type2 Price2 Type3 Price3
John 12 100 23 89 52 431

Type1, 2 and 3 being the Count of type1, 2 and 3
Price being the Total Price of Type1, 2 and 3

I tried Count(*), but with this method, you have to group by type and the data displays down and not accross.

Any help would be great,
Thank you

RichO
04-22-2004, 06:18 PM
I think the DCount function will work for what you need. You can use it in a calculated field on a report. The syntax would be:

=DCount("[TypeField]", "[MyTable]", "[TypeField] = 1")

This will return the count of records in MyTable where TypeField is equal to 1. You can do a separate one of these for each text box.

Access Help explains the use of DCount fairly well.

Pat Hartman
04-23-2004, 06:48 AM
Select "Count of 1,2,3" as CountName, Count(*) As CountofItems, Sum(Price) As SumOfPrice
From YourTable
Where Type In(1,2,3)
Group By "Count of 1,2,3";