+ Reply to Thread
Results 1 to 25 of 25

Listing unique values and summing w/o a pivot table

  1. #1
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Listing unique values and summing w/o a pivot table

    Hello:

    I have a set of data that I'm trying to identify the unique values in a column and then sum the related quantites against each of those values:

    Code Qty
    22 10
    23 20
    22 10
    24 20
    22 10

    Results:
    Code Qty
    22 30
    23 20
    24 20

    I'm trying to do this without an advanced filter of pivot table since the data in the columns is populated over time. From what I know, the filter is a one shot run and the pivot table needs to be refreshed.

    Also the data to be reviewed would be limited to a specifc array (rows/colums).

    Is there a basic formula to accomplish this?
    Last edited by Drew Goldberg; 05-30-2009 at 04:26 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Listing unique values and summing w/o a pivot table

    Try a SUMIF:

    =SUMIF(A:A,A1,B:B)
    ...or...
    =SUMIF(A:A,22,B:B)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    JBeaucaire:

    I was able to use the "SUMIF(A:A,A1,B:B)" formula for the summing portion but what would allow for reviewing and listing the unique values from a column (22, 23, 24...)?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Listing unique values and summing w/o a pivot table

    In an adjacent column put this array formula, let's say you put it in C1:

    =INDEX(A$1:A$100,MATCH(0,COUNTIF(A$1:A$100,"<"&A$1:A$100),0))

    That's an array, so press CTRL-SHIFT-ENTER to confirm the formula. Next, in C2, enter this array formula:

    =IF(COUNTIF(A$1:A$100,">"&C1), INDEX(A$1:A$100, MATCH(COUNTIF(A$1:A$100,"<="&C1), COUNTIF(A$1:A$100,"<"&A$1:A$100),0)),"")

    ...also confirmed with CTRL-SHIFT-ENTER. Now copy that 2nd formula down as far as needed to get all your values to appear. These two formulas not only present all your values, it presents them sorted, too.

    Then do your SUMIF in D1:
    =IF(C1="","",SUMIF(A:A,D1,B:B)

    ...copied down.

  5. #5
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Listing unique values and summing w/o a pivot table

    For getting unique values u can use the following formula. But this one is array formula. Must be confirmed with Ctrl+Shift+Enter

    =INDEX(A1:A5,SMALL(IF(MATCH(A1:A5,A1:A5,0)=ROW(INDIRECT("1:5")),ROW(INDIRECT("1:5")),""),ROW(INDIRECT("1:5"))))
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  6. #6
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    I just posted and saw the recent replies. I'lll try the recommendations and repost.

    I have attached a spreadsheet to assist with the requirements.
    Attached Files Attached Files
    Last edited by Drew Goldberg; 05-27-2009 at 05:07 PM. Reason: Misposted

  7. #7
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    I'm trying the formula "=INDEX(A1:A5,SMALL(IF(MATCH(A1:A5,A1:A5,0)=ROW(INDIRECT("1:5")),ROW(INDIRECT("1:5")),""),ROW(INDIREC T("1:5"))))" which works when the array is set to those column cells that have a value.

    However, if I extend it to a range with and without values, a #N/A is returned.

    Is a modification required for cells without values?

    I'm still working on the other option.

  8. #8
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Listing unique values and summing w/o a pivot table

    For table u posted try

    =INDEX(B3:B9,SMALL(IF(MATCH(B3:B9,B3:B9,0)=ROW(INDIRECT("1:"&ROWS(3:9))),ROW(INDIRECT("1:"&ROWS(3:9))),""),ROW(INDIRECT("1:"&ROWS(3:9)))))

  9. #9
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Listing unique values and summing w/o a pivot table

    Based on the worksheet u've posted

  10. #10
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Listing unique values and summing w/o a pivot table

    Quote Originally Posted by Drew Goldberg View Post
    I'm trying the formula "=INDEX(A1:A5,SMALL(IF(MATCH(A1:A5,A1:A5,0)=ROW(INDIRECT("1:5")),ROW(INDIRECT("1:5")),""),ROW(INDIREC T("1:5"))))" which works when the array is set to those column cells that have a value.

    However, if I extend it to a range with and without values, a #N/A is returned.

    Is a modification required for cells without values?

    I'm still working on the other option.
    If u extend the range with or w/o values it would return N/A error. to fox it u can use this formula. This formula for workbook u posted...

    =IF(ISERROR(INDEX(B3:B39,SMALL(IF(IF(ISERROR(MATCH(B3:B39,B3:B39,0)),"",MATCH(B3:B39,B3:B39,0))=ROW(INDIRECT("1:"&ROWS(3:39))),ROW(INDIRECT("1:"&ROWS(3:39))),""),ROW(INDIRECT("1:"&ROWS(3:39)))))),"",INDEX(B3:B39,SMALL(IF(IF(ISERROR(MATCH(B3:B39,B3:B39,0)),"",MATCH(B3:B39,B3:B39,0))=ROW(INDIRECT("1:"&ROWS(3:39))),ROW(INDIRECT("1:"&ROWS(3:39))),""),ROW(INDIRECT("1:"&ROWS(3:39))))))

  11. #11
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    ContaminatedWitExcel:

    When I use the recent formula and try and pull it down over a range over cells, the cells adjust (as expected). So I use "$" for each cell in the formula, but this returned a "0".

    I seem to be experiencing different errors with each attempt to recreate this scenario.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Listing unique values and summing w/o a pivot table

    Have you tried the two standard formulas suggested in post #4? They seem to work perfectly.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    Got it!

    Moving on to the second column for time - that looks more straight forward.

    Actually got to run home but will resume this evening.

    Thanks for the guidance.
    Last edited by Drew Goldberg; 05-27-2009 at 07:35 PM. Reason: Updated note

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Listing unique values and summing w/o a pivot table

    Hi Drew, seems you have resolved but given it's (seemingly) related to the other thread I figured I'd add my 2 cents worth

    You could use a SUMPRODUCT to store count of unique ID's

    eg:

    J1: =SUMPRODUCT(1/COUNTIF($B$3:$B$9,$B$3:$B$9&""))

    Then you can populate your table without need for Arrays / Helpers using:

    F3: =IF(ROWS(F$3:F3)>$J$1,"",SMALL($B$3:$B$9,1+COUNTIF($B$3:$B$9,"<="&N(F2))))

    G3: =IF(N($F3),SUMIF($B$3:$B$9,$F3,$C$3:$C$9),"")

    H3: =IF(N($F3),COUNTIF($B$3:$B$9,$F3),"")

    all copied down as far as desired.

    This is all based on the assumption that your Codes are numbers - I think this is a safe assumption.

  15. #15
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Listing unique values and summing w/o a pivot table

    Quote Originally Posted by JBeaucaire View Post
    Have you tried the two standard formulas suggested in post #4? They seem to work perfectly.
    Nice trick.
    Very nice. Its very useful.

  16. #16
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    DonkeyOte:

    What adjustments would be needed if there was a blank cell in between the set of numbers?

    When I added a row, the value in J3 jumped from 4 to 5 which threw of F, G, & H when it they tried to look for a 5th unique value.

    I did this to see if I could use the formulas to handle two sets of data in the same column.

  17. #17
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Listing unique values and summing w/o a pivot table

    If by J3 you meant the SUMPRODUCT you would add a clause to discount Nulls/Blanks - it's omission was short sighted of me in the first instance, ie:

    Please Login or Register  to view this content.
    That said given you're always looking for numbers you could use ISNUMBER test instead (so only numbers would be considered as valid)

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    JBeaucaire:

    Got the formula working and as you indicated it sorted as well. One other feature is the ability to handle blank cells in the column.

    Thanks you for your assistance.

  19. #19
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    DonkeyOte:

    I'll definitely consider those tests from now on as they add flexibility to the formulas.

    Thank you!
    Last edited by Drew Goldberg; 05-30-2009 at 07:45 PM. Reason: spelling

  20. #20
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    Okay, here's another wrinkle:

    What if there were 5 cell ranges in a column; B2:B6, B10:B14, B18:B22,... with values in between that were to be ignored.

    i.e.

    B2 22
    B3 23
    B4 22
    B5 24
    B6 21
    B7 1002
    B8 263
    B9 289
    B10 22
    B11 23
    B12 22
    B13 21
    B14 21

    B15 1001
    B16 1003
    B17 872


    Is this a matter of excluding the undesirable rows (if they are already known)?
    Last edited by Drew Goldberg; 05-30-2009 at 08:26 PM. Reason: color change

  21. #21
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Listing unique values and summing w/o a pivot table

    You would first need to elaborate in terms of how you know certain rows are to be ignored - is this based on a valid ID range of sorts (eg 20-200) ?

  22. #22
    Registered User
    Join Date
    04-12-2008
    Location
    SF BAY Area
    Posts
    32

    Re: Listing unique values and summing w/o a pivot table

    Yea.

    I'm in the position of having a completed template filled out on a daily basis and then copying that to a separate workbook to capture the "daily results".

    So I end up with a repeating range (separate days results) listed below one another that I'm trying to collate into a list. Thus, the actual desired rows can be identified in advance.

    As a quick fix, I adjusted the data in the column so that only the cells I was looking for had actual numbers and utilized your ISNUMBER suggestion.

    By the way, any suggestion on preventing the copying/pasting exercise? I didn't see anyway around since I have a single blank template that gets written over each day. I guess I could have a set of them to represent each day and link the results to another formatted page but this doesn't seem to allow me to lock in the results once entered.

  23. #23
    Registered User
    Join Date
    01-31-2013
    Location
    Brisbane, Australia. high and dry
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Listing unique values and summing w/o a pivot table

    Quote Originally Posted by JBeaucaire View Post
    Have you tried the two standard formulas suggested in post #4? They seem to work perfectly.
    Rehashing an old thread.

    This worked fine for me, or so I thought.

    In your attached file, if B3 has data and any cell from B4 down is empty, it will just keep going down the row until it finds more data

    The data I am using sometimes starts with a blank cell or two in cell B3, is there a way of error checking down the column, say 4 rows, to see if there is data below an empty B3 cell

    Bob
    Last edited by bungslea; 02-12-2013 at 08:51 PM.

  24. #24
    Registered User
    Join Date
    01-31-2013
    Location
    Brisbane, Australia. high and dry
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Listing unique values and summing w/o a pivot table

    Please bump ( to few characters )

  25. #25
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Listing unique values and summing w/o a pivot table

    @bungslea,

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    HTH
    Regards, Jeff

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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