+ Reply to Thread
Results 1 to 18 of 18

returning distinct values from a table

  1. #1
    Registered User
    Join Date
    07-30-2014
    Location
    miami, fl
    MS-Off Ver
    excel 2010
    Posts
    4

    returning distinct values from a table

    i am having a bit of trouble figuring out a way to make a formula for this. i have a set of cells and i want it to return all of the distinct or unique values within that matrix. for example, lets say this table charts how many sales an employee makes in a week

    sun mon tues weds thurs fri sat
    john doe 1 0 3 2 3 0 0
    jane doe 0 8 0 1 0 7 0
    james doe 3 3 2 3 2 1 1

    the desired output would be: 0,1,2,3,7,8

    i dont want to be copying all of the cells or doing a lot of manipulation - i know i can copy, sort, and get unique values that way - i want a formula where as i plug in values, this field is updated to include all of the distinct or unique values. i am hoping someone can help me out - thanks!

  2. #2
    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
    43,986

    Re: returning distinct values from a table

    Is this something like what you had in mind?
    Attached Files Attached Files
    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

  3. #3
    Registered User
    Join Date
    07-30-2014
    Location
    miami, fl
    MS-Off Ver
    excel 2010
    Posts
    4

    Re: returning distinct values from a table

    hi glenn - thanks for the quick response. close, but not quite. with this i could be getting a lot of different values - ones i might not be able to predict, which makes col J impossible to set up.

    using your example, what i am looking for is a formula that would output "0, 1, 2, 3, 4, 7" in some manner.

    im not sure if i did a good job of explaining myself. do you have any other ideas?

  4. #4
    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
    43,986

    Re: returning distinct values from a table

    Are you OK to use helper columns, that can be hidden?

  5. #5
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: returning distinct values from a table

    Hi,

    Do you want the results concatenated into a single cell, comma-separated (which will require VBA), or are you happy with each result being in its own cell?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  6. #6
    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
    43,986

    Re: returning distinct values from a table

    Try this, then. You can always hide row J. Both equations are ARRAY formulas and MUST be set by using CTRL + SHIFT + ENTER and NOT just enter...
    Attached Files Attached Files

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: returning distinct values from a table

    You can also do it without a helper column if you really insist (though I see no real reason to avoid Glenn's set-up), if you first go to Name Manager and define:

    Name: Range1
    Refers to: =$B$2:$H$4

    (Or whatever happens to be the range in question.)

    Name: Arry1
    Refers to: =ROW(INDIRECT("1:"&COLUMNS(Range1)*ROWS(Range1)))

    The array formula** is then:

    =IFERROR(SMALL(IF(FREQUENCY(IF(Range1<>"",Range1),Range1),N(OFFSET(INDEX(Range1,1,1),INT((Arry1-1)/COLUMNS(Range1)),MOD(Arry1-1,COLUMNS(Range1)),,))),ROWS($1:1)),"")

    Copy down until you start to get blanks.

    Note that this solution assumes that the values in the range are all numerical, just as in the example you gave.

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: returning distinct values from a table

    I obviously don't "get" what you are after.
    Last edited by newdoverman; 07-30-2014 at 06:02 PM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  9. #9
    Valued Forum Contributor
    Join Date
    10-14-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2019
    Posts
    353

    Re: returning distinct values from a table

    I added some helper columns which can be hidden.
    The number of formulas done must be greater then the number of values in your range
    Attached Files Attached Files
    Kind regards,
    Piet Bom

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: returning distinct values from a table

    Maybe I figured out what you want. Does this come close to what you want?
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-30-2014
    Location
    miami, fl
    MS-Off Ver
    excel 2010
    Posts
    4

    Re: returning distinct values from a table

    first i would like to thank all of you for your help so far. i have been trying a lot of your different approaches and excel keeps crashing. i have a little over 1k rows (7k cells) of data and its really bogging things down. i may just be out of luck as i know my data set will continue to grow.

    ive tested a lot of these with smaller sets and it definitely works, just expanding this out is giving me problems. i may have to hang this one up unless there is something less taxing.

    thank you everybody for your help, let me know if anybody can think of anything more "efficient"! also for reference, i have been a column of iferror(small( and another column with the iferror array formula, which most of you suggested.

  12. #12
    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
    43,986

    Re: returning distinct values from a table

    I copied the data down for 1000 rows. See attached. If I chane a number anywhere in the data table, the results take about 1 second to update. Try it...
    Attached Files Attached Files

  13. #13
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: returning distinct values from a table

    Here is my attempt. I have filled all 7000 cells and in column all 7000 values are retrieved then in column K the unique values are obtained. Column L then arranges the values in column K in order.

    File removed because of difficulty opening.
    Last edited by newdoverman; 07-31-2014 at 04:52 PM.

  14. #14
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: returning distinct values from a table

    @Glenn Kennedy

    Unless I am missing something, it appears that your workbook is only processing the first 31 rows of the range and column J is retrieving 1000 of the possible 7000 values.

    I think that it is just a matter of the ranges not being correct.

  15. #15
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: returning distinct values from a table

    If you are open to a VBA solution, please find the attached sheet to see if this works as per your requirement. (Used Glenn's sheet for data)
    Click on the Green Button on the sheet to get the desired output in column K.


    Edit: I attached the wrong sheet earlier. The correct sheet has been attached now.
    Attached Files Attached Files
    Last edited by sktneer; 07-31-2014 at 02:49 PM. Reason: Wrong Attachment.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  16. #16
    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
    43,986

    Re: returning distinct values from a table

    Ndm. Oops. You may be right ... if this hasn't been solved by the morning, I'll take another look.

  17. #17
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: returning distinct values from a table

    Apologies. I was being lazy using this IFERROR set-up, not to mention the fact that it's terribly inefficient.

    Much better is to enter in e.g. J1:

    =SUMPRODUCT((Range1<>"")/COUNTIF(Range1,Range1&""))

    The array formula** then becomes (I've made a small modification as well):

    =IF(ROWS($1:1)>$J$1,"",SMALL(IF(FREQUENCY(IF(Range1<>"",0+Range1),0+Range1),N(OFFSET(INDEX(Range1,1,1),INT((Arry1-1)/COLUMNS(Range1)),MOD(Arry1-1,COLUMNS(Range1)),,))),ROWS($1:1)))

    but this time will only calculate the large, resource-heavy array part if the relative row number of the cell in which the formula is placed is less than or equal to the number of expected returns. Otherwise, the IF clause will force this part to remain uncalculated.

    (In the previous version, the array was calculating in every cell to which you copied the formula, thus putting unnecessary demand on resource.)

    Try this version and let me know if that improves things much.

    Regards

  18. #18
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: returning distinct values from a table

    see the attached file
    Attached Files Attached Files
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

+ 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. Returning multiple distinct/repeating values for vlookup or index-match
    By amatvien in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-21-2018, 01:14 PM
  2. returning distinct values from a table
    By dc51786 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-31-2014, 06:15 AM
  3. Pivot Table with Distinct Values
    By Ziggy4e in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-21-2014, 11:11 PM
  4. How to count distinct values from table in pivot table
    By gopijadhav in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-04-2014, 07:14 AM
  5. Data Validation Returning only distinct values from a list
    By JI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2006, 06:45 PM

Tags for this Thread

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