Results 1 to 6 of 6
  1. #1
    weilder02 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    3

    How to calculate how many of a attribute you have


    Basically I have a table that has a userID, a contactID and a type (friend, neutral & block) - what I want to do is to count how many of each type each user has - is there an easy way to do this?

  2. #2
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    You can create a query using your user field and type. Then select "Totals" from the toolbar and in the "Total" column. Select "Group By" for the user and "Count" for the "Type".

  3. #3
    weilder02 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    3
    That does it sort of - that gives me the userID with the total of how many contacts they have - what i want it to do is to give a count of how many of each type they have eg:

    Results I'm getting at the moment:

    UserID CountOfType
    1 6
    2 6

    What I'd Like it to give:

    UserID Friend Neutral Block
    1 4 1 1
    2 3 3 0

  4. #4
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    You can do that a few different ways. Probably the best would be to use a crosstab query. I won't write all the specifics on it but if you do a google search on access crosstabs, you'll find all the information that you need. Another approach would be to create a field for each of the types in a query like this.

    Friend:IIF(nz([Type])="Friend",1,0)

    You would do this for each of the types and set those fields to "Count". This wouldn't be the best way to do it though because it's hard coded. You would need to create a new field each time a different type is added or modified. The crosstab would be your best bet.

  5. #5
    weilder02 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    3
    Thanks for that - the crosstab query worked beautifully

  6. #6
    Datagopherdan is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Dec 2008
    Posts
    220
    Glad you got it working.

    Quote Originally Posted by weilder02 View Post
    Thanks for that - the crosstab query worked beautifully

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculate Interest
    By jgelpi16 in forum Queries
    Replies: 3
    Last Post: 08-19-2016, 08:01 PM
  2. Unnhide Attribute?
    By thorsonb in forum Access
    Replies: 1
    Last Post: 03-30-2010, 10:21 PM
  3. DB to calculate ceramic glazes
    By pichon in forum Access
    Replies: 4
    Last Post: 03-15-2010, 07:50 PM
  4. Calculate avg in a report
    By bob006 in forum Reports
    Replies: 1
    Last Post: 11-18-2009, 06:31 PM
  5. calculate holidays
    By barkarlo in forum Queries
    Replies: 0
    Last Post: 12-20-2006, 06:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums