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?
correlateAsked:
Who is Participating?
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

0
Ryan ChongCommented:
if you want to use CountIF formula in Excel, you can try this.
28711853.xlsx
0
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ryan ChongCommented:
try

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

0
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 :)

E.g.

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

Open in new window

0

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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.