+ Reply to Thread
Results 1 to 12 of 12

Sum of values in column based on unique IDs in another column

  1. #1
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Sum of values in column based on unique IDs in another column

    Hi All,

    Sample worksheet attached with expected results.

    I require a formula that will do a sum of the values in column B but only for the unique values in Column A where the total tokens > 1. Column A contains duplicate values.

    For example if the same ID from column A appears twice with 2 tokens on each row. The total tokens for this user is 2, not 4.

    In the sample worksheet there are 4 unique ID's where the total tokens >1. So the sum of tokens is 9.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Sum of values in column based on unique IDs in another column

    Since you are in 365, Use logic that handles these old problems!

    Please Login or Register  to view this content.
    --------- Just read your post a little more - that is not your solution... will take another look in a minute - Work calls
    Last edited by ELeGault; 04-21-2022 at 06:01 PM.
    -If you think you are done, Start over - ELeGault

  3. #3
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Sum of values in column based on unique IDs in another column

    Try this

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Sum of values in column based on unique IDs in another column

    Let me ask, would an ID appear more than once with different values?
    In your sample data, what I provided will always work... but if ID 1234 has 2, and then 2, and then 1... the 1 will be lost

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Sum of values in column based on unique IDs in another column

    Maybe:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Sum of values in column based on unique IDs in another column

    ELeGault - An ID will never appear more than once with different values. Your solution works.

    TMS - Your solution also works however I think it is dependant on columns A and B being next to each other. In my real data the columns aren't next to each other which causes the formula to fail.


    I updated the sample data slightly to include another condition that I missed from post #1. Column P must also = yes.

    So in summary a Sum of the values in column K but only for the unique values in Column A where the values in Column K > 1 AND Column P = Yes.
    Attached Files Attached Files

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,937

    Re: Sum of values in column based on unique IDs in another column

    Try this adaptation:

    =SUM(FILTER(UNIQUE(FILTER(A2:K23,K2:K23>1)),{0,0,0,0,0,0,0,0,0,0,1}))

    I am sure you have been told before that it is ESSENTIAL that you present REALISTIC data from the outset - ANY change in layout or detail you've missed leads to goalposts being constantly shifted, which is very frustrating for your helpers and means a lot of time wasted.

    PS Maybe this is what you want?

    =SUM(FILTER(UNIQUE(FILTER(A2:P23,(K2:K23>1)*(P2:P23="YES"))),{0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}))

    Or this?

    =COUNT(UNIQUE(FILTER(A2:A23,(K2:K23>1)*(P2:P23="YES"))))
    Attached Files Attached Files
    Last edited by AliGW; 04-22-2022 at 04:46 AM. Reason: Workbook attached.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Sum of values in column based on unique IDs in another column

    or in case all those zeros make your eyes water...


    =SUM(INDEX(UNIQUE(FILTER(A2:P23,(K2:K23>1)*(P2:P23="YES"))),,11))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,937

    Re: Sum of values in column based on unique IDs in another column

    Glenn - the one with the zeros doesn't actually return the right answer. I think my final offering does, though.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Sum of values in column based on unique IDs in another column

    @makaveeti:
    TMS - Your solution also works however I think it is dependant on columns A and B being next to each other. In my real data the columns aren't next to each other which causes the formula to fail.
    As Ali has pointed out, you need to post a realistic representation of your data. No-one but you knows what it really looks like. You can only get working solutions based on what you share.

  11. #11
    Forum Contributor
    Join Date
    07-25-2017
    Location
    UK
    MS-Off Ver
    Office 365 Excel Version 2202 Build 16
    Posts
    184

    Re: Sum of values in column based on unique IDs in another column

    AliGW & TMS - Apologies and understood. Sometimes I overlook subtleties which I don't think would be an issue however this thread proves I shouldn't.


    AliGW - The second formula works - =SUM(FILTER(UNIQUE(FILTER(A2:P23,(K2:K23>1)*(P2:P23="YES"))),{0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0}))

    Glenn Kennedy - Your solution also works great.

    Marking thread as solved.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,937

    Re: Sum of values in column based on unique IDs in another column

    So the expected result was not 9, nor was it 3 (as suggested in the workbook), but 7 ...

    You managed to make this all very confusuing, but glad you got there in the end. Think a bit more carefully before posting a new thread, please. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Count unique values from one column based on value in other column
    By cmav in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-28-2020, 03:57 PM
  2. Replies: 7
    Last Post: 10-23-2018, 10:18 AM
  3. Counting cells in one column based on unique values in another column
    By 3SixOne in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-13-2017, 06:23 AM
  4. Replies: 2
    Last Post: 07-04-2017, 03:20 PM
  5. [SOLVED] VBA Creating a list of unique values from one column based on criteria from another column
    By bilbo85 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2016, 02:38 PM
  6. Replies: 2
    Last Post: 08-19-2015, 10:22 AM
  7. [SOLVED] Filter rows based on unique values in one column + specific value in another column
    By Dieneces in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2013, 09:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1