Results 1 to 11 of 11
  1. #1
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6

    Removing duplicates only in count

    Hello,
    I have huge database around 2.5 lakh entries. I need to display some data in a specific format, but I am not able to do so.
    The data looks something like this:
    Customer Number SP
    647061 AG
    647061 SP01
    647061 AG
    208689 AG
    208689 SP02
    208689 SP03
    51982 AG
    51982 GG
    286432 AG
    286432 AG
    63482 AG
    63482 SP01
    63482 SP02
    63482 SP03


    Now I am trying to create a pivot(in excel) with the data which is easy as shown below.
    Row Labels Count of Customer Number
    AG 7
    GG 1
    SP01 2
    SP02 2
    SP03 2
    Grand Total 14

    But here I do not want duplicates within individual rows. For e.g. AG shows 7, but the same customer 647061 has occurrence = 2. I want this to be counted as 1. But I would like it to be counted again for SP01. I tried a lot, but could not reach any conclusions. Please help.



    regards.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    So do you want a list of Customers or SP?

    If 1 customer can have many SP, then if you include Customer and Sp I think you'll get duplicates.
    The other choice is to take Customer and only 1 SP (regardless if the Customer has 1 or 3 SPs).

  3. #3
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6
    Hello,

    I want count of customers for an SP, but like I said removing duplicates from the no of customers.

    I tried a solution which works in excel, but I do not know how to replicate in access.

    regards.

    Quote Originally Posted by orange View Post
    So do you want a list of Customers or SP?

    If 1 customer can have many SP, then if you include Customer and Sp I think you'll get duplicates.
    The other choice is to take Customer and only 1 SP (regardless if the Customer has 1 or 3 SPs).

  4. #4
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6

    Syntax error missing operator

    Hello,

    In piece of code below, I am getting syntax error

    syntax error (missing operator) in query expression 'WHERE [Product Version]='ABC'

    SELECT SP,
    WHERE [Product Version]='ABC',
    COUNT(*) AS count_distinct_Cust
    FROM (SELECT DISTINCT
    SP,
    [Customer Number]
    FROM DataPV
    ) AS tmp
    GROUP BY SP;

    please help.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    First comma is a syntax error
    WHERE comes after FROM

    see this for syntax of SELECT

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Try

    Code:
    SELECT Count([%$##@_Alias].CUSTOMERNUMBER) AS CountOfCUSTOMERNUMBER, [%$##@_Alias].SP
    FROM (SELECT DISTINCT(customernumber & " " & SP) AS XX,CustSP.CUSTOMERNUMBER , CustSP.SP
    FROM CustSP
    )  AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].SP;
    which gives

    Code:
    CountOfCUSTOMERNUMBER SP
    5 AG
    1 GG
    2 SP01
    2 SP02
    2 SP03

  7. #7
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6
    Hello,

    I now wrote it as
    SELECT SP, COUNT(*) AS count_distinct_Cust
    FROM (SELECT DISTINCT SP, [Customer Number] FROM DataPV) AS tmp
    WHERE [Product Version] = 'ABC'
    GROUP BY SP;

    But it is not really giving the right value. It is even calculating the data when Product version is equal to any other value as well.
    Do you know what could be the reason.

  8. #8
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6
    Hello,
    It gives only the 0 for Count of customer number.

    For the same query I wrote the code which I mentioned in other thread located at
    MOD EDIT: threads merged


    Please suggest if that will work.
    Last edited by June7; 09-07-2014 at 12:12 PM.

  9. #9
    tchmenot is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2014
    Posts
    6
    This is solved...

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    How about showing us your solution. Someonelse with similar problem may be searching for an answer.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You are selecting records from a dataset that does not have [Product Version] field. How can you use it as filter criteria if the data is not present? I am surprised this query runs at all.

    Review http://allenbrowne.com/subquery-01.html#Aggregation

    Maybe:

    SELECT SP, Count([Customer Number]) AS count_distinct_Cust FROM (SELECT DISTINCT SP, [Customer Number] FROM DataPV WHERE [Product Version]="ABC") AS tmp GROUP BY SP;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Removing Duplicates
    By hefferwolfe in forum Queries
    Replies: 1
    Last Post: 04-30-2014, 04:31 AM
  2. Merging & removing duplicates
    By Johin.b in forum Access
    Replies: 1
    Last Post: 08-09-2013, 03:07 PM
  3. Removing duplicates
    By DAVID W in forum Access
    Replies: 5
    Last Post: 12-21-2011, 03:15 PM
  4. Removing duplicates & printing uniques
    By sp3cialed in forum Access
    Replies: 1
    Last Post: 08-06-2011, 12:31 AM
  5. Need help removing duplicates
    By warlock in forum Queries
    Replies: 1
    Last Post: 04-14-2011, 03:44 PM

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