MS Access version of Excel's CountIf

Dear Experts,

I'm doing some de-duplication work on a membership database and, having exported the results I have created a new table "Post123WithGradeAChecks". This table contains various fields including the GUID of the original record and the field I wish to query [NameAndCo].

An example would be:

[GUID]     [NameAndCo]
123          JohnSmithApple
456          JoeSpenceMicrosoft
789          PeterWinApple
643          JohnSmithApple

I need to create a query which counts how many times NameAndCo appears in the table, using the example above the results of this query would be:

[GUID]     [NameAndCo]              [results]
123          JohnSmithApple                 2
456          JoeSpenceMicrosoft          1
789          PeterWinApple                   1
643          JohnSmithApple                 2

The data set is quite large, otherwise I would do this in excel using a countif formula

Can anybody help?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Use the Sigma icon in the query designer to great a Totals query. As SQL:

SELECT  [NameAndCo] ,
        COUNT(*) AS Cnt
FROM    YourTable
GROUP BY [NameAndCo];

Open in new window

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
if you want to use CountIF formula in Excel, you can try this.
correlateAuthor Commented:
Hi ste5an

Thanks for this - it works, but only if I don't include any other fields from the record (i.e. the GUID) which I need to include as that's the link back to the original record.

Any ideas?

Many thanks
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:

SELECT  a.[GUID], a.[NameAndCo] , b.cnt
FROM    YourTable a inner join (select [NameAndCo], count(*) cnt from YourTable group by [NameAndCo]) b
on a.[NameAndCo] = b.[NameAndCo]
order by a.[GUID]

Open in new window

ste5anSenior DeveloperCommented:
When you include the GUID you'll get only 1 as count?

This means that the the GUID (global unique ID) makes your rows unique :)


        O.[NameAndCo] ,
        ( SELECT    COUNT(*)
          FROM      YourTable I
          WHERE     I.[NameAndCo] = O.[NameAndCo]
        ) AS cnt
FROM    YourTable O;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
correlateAuthor Commented:
perfect, works a treat - thank you very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.