+ Reply to Thread
Results 1 to 6 of 6

Choose Random Value Based On List

  1. #1
    Registered User
    Join Date
    10-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Choose Random Value Based On List

    Hi everyone,

    I've got a toughy question for you, but it bears some explaining.

    I have a growing list of people that have given me referrals to our agency. At the end of every month, we conduct a lottery to see who of the referral-senders will win a gift card. Each time someone gives me a referral, I enter their name once into a column in Excel. However, I can receive multiple referrals from one person, and that is fine. In fact, the more referrals they send me, the greater chance of them being chosen for the lottery.

    Here is what I would like to do:

    Column A: Name of Person
    Column B: # of total referrals they have sent.

    I would like to have a cell that selects the name of one person in that list, taking into account the total number of referrals he/she has sent in.

    For example:
    - Bob has sent in 10 referrals
    - Sally has sent in 2 referrals
    - Justin has sent in 8 referrals.

    Column A only has 3 names, and I don't want the probability of choosing any given person to be a 1/3 chance. Rather, I want Excel to know that Bob has a 50% chance of winning the lottery, while Sally has a 10% chance, and Justin has a 40% chance. Consequently, based on that information, I want Excel to choose a name for me.

    How could I set this up?

    Thanks!

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Choose Random Value Based On List

    something like this maybe
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Random Value Based On List

    Starting your data in row 2 (A2:B4), in C1, enter 0, in C2 dragged down
    =B2/SUM(B:B)+C1

    Your pick
    =INDEX($A$2:$A$4, MATCH(RAND(),$C$1:$C$3,1))

    You can hide column C
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    10-22-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Choose Random Value Based On List

    Thank you both! Both ideas work flawlessly.

    I have a question though ChemistB - Forgive my ignorance, but why does column C's formula need the +C1 (and subsequently +C2, +C3, etc.) What's the rationale?

    Also, martindwilson - can you explain Column F's formula? Ex. =IF(E3="","",RAND())

    Thanks!
    Last edited by kblaine; 04-20-2011 at 10:39 AM.

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choose Random Value Based On List

    In my spreadsheet, the rand function spits out a # between 0.0001 and 0.9999 (more or less) which relates directly to a percentage between 0 and 100. Column C gives each person, based on the # of referrals, a chunk of that 100%. Let's say that each person (4 people) got the same amount of referrals. Then each would have 0.25 or 25%. When the MATCH function looks there, we need those numbers to be different and adding to 100% (or 1). Thus the +C1 adds the % of the previous people to that person so we cover the entire range like so
    Tom 0.25
    Bob 0.50
    Bill 0.75
    Larry 1
    Hope that makes sense.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Choose Random Value Based On List

    mine just sticks a random number ,if cell in that case e3 is not blank ,then picks the largest there is more chance the large number will appear in someone with 11 entries than 2

+ 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