+ Reply to Thread
Results 1 to 8 of 8

Extracting a set of random values with no duplicates and one condition

  1. #1
    Registered User
    Join Date
    10-23-2021
    Location
    London
    MS-Off Ver
    Excel Version 16.54
    Posts
    3

    Extracting a set of random values with no duplicates and one condition

    Hey Forum,

    Nice to meet you all! I have a column for shipment IDs and another column for agents. What I'm trying to achieve is, generate 4 random shipment IDs that correspond to each agent. Through some extensive googling and browsing various threads in this forum, I have managed to achieve that but now I notice the values are not unique. For example, for someone like Agent 4 who only has 5 shipment IDs, you often see E and F columns having the same value. What I want is that, all 4 randomly selected shipments IDs for each agent would be unique, with no duplicates. I guess this would be the case of adding an additional IF statement and updating the end of the formula to COUNTIFS to check the previous Shipment ID columns but for the life of me I can't figure it out.

    Thanks in advance for any tips!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,152

    Re: Extracting a set of random values with no duplicates and one condition

    Using a helper column

    in C

    =rand()

    copy down

    in E2

    =INDEX($A$1:$A$43,MATCH(LARGE(OFFSET($C$1,MATCH($D2,$B$1:$B$43,0),,COUNTIF($B:$B,$D2)),COLUMNS($A$1:A$1)),OFFSET($C$1,MATCH($D2,$B$1:$B$43,0),,COUNTIF($B:$B,$D2)),0)+MATCH($D2,$B$1:$B$43,0))

    copy across and down
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Extracting a set of random values with no duplicates and one condition

    Hi & welcome to the board.
    Another option in E2 dragged down only
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-23-2021
    Location
    London
    MS-Off Ver
    Excel Version 16.54
    Posts
    3

    Re: Extracting a set of random values with no duplicates and one condition

    Thank you so much both!

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Extracting a set of random values with no duplicates and one condition

    Glad to help & thanks for the feedback.

  6. #6
    Registered User
    Join Date
    10-23-2021
    Location
    London
    MS-Off Ver
    Excel Version 16.54
    Posts
    3

    Re: Extracting a set of random values with no duplicates and one condition

    Thanks again! However it looks like the formula doesn't return the correct results if an agent has 1 shipment ID only. For example, it returns Agent 3's first shipment ID for Agent 2 here:
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Extracting a set of random values with no duplicates and one condition

    Did you try the formula I suggested?

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,152

    Re: Extracting a set of random values with no duplicates and one condition

    Try

    =IFERROR(INDEX($A$1:$A$50,MATCH(LARGE(OFFSET($C$1,MATCH($D2,$B$1:$B$50,0)-1,0,COUNTIF($B:$B,$D2)),COLUMNS($A$1:A$1)),OFFSET($C$1,MATCH($D2,$B$1:$B$50,0)-1,,COUNTIF($B:$B,$D2)),0)+MATCH($D2,$B$1:$B$50,0)-1),"")

+ 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. Random Numbers assigned to static values multiple times no duplicates....?
    By rhattala in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 11-24-2014, 09:40 PM
  2. Replies: 1
    Last Post: 01-22-2013, 03:45 PM
  3. Replies: 3
    Last Post: 09-30-2012, 03:03 PM
  4. [SOLVED] Extracting multiple values based on the condition...Pls help (Urgnt)
    By krratheesh80 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-21-2012, 10:06 AM
  5. Replies: 2
    Last Post: 08-28-2012, 10:41 PM
  6. Replies: 6
    Last Post: 05-06-2011, 02:17 PM
  7. Extracting random values in a list
    By Blondegirl in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-28-2008, 07:51 AM

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