Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Create column with random values from list

Hi all,

I want to define a list a text values, and then create a new column which selects any value from that list.

Can anyone please tell me how to select any value from a list?

e.g. create a new column containing any values from {"Apples", "Bananas", "Pears"}

  • Anonymous 

    Please create a Rank column which display the location of text cell.

    Rank = RANKX(Table1,Table1[Name],,ASC)


    Then, we select any location according the random number between 1 to the max location. Use LOOKUPVALUE function grab the values.

     

    New Column = LOOKUPVALUE(Table1[Name],Table1[Rank],RANDBETWEEN(1,MAX(Table1[Rank])))

    Please refer to the following screenshot.


    Best Regards,
    Angelia

8 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      @smoupre wrote:

      Number.Random

       

      or

       

      Number.RandomBetween:


      Hi, thanks for your reply but I was looking for solutions for text values.

      • tringuyenminh92's avatar
        tringuyenminh92
        Memorable Member
        Same as we create sample data in excel, u just create one master table with 2 Column(id,text) and in fact table you add one column as reference column by random in range of id column of table master. After that make the relationship between 2 table.
  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft Employee

    Anonymous 

    Please create a Rank column which display the location of text cell.

    Rank = RANKX(Table1,Table1[Name],,ASC)


    Then, we select any location according the random number between 1 to the max location. Use LOOKUPVALUE function grab the values.

     

    New Column = LOOKUPVALUE(Table1[Name],Table1[Rank],RANDBETWEEN(1,MAX(Table1[Rank])))

    Please refer to the following screenshot.


    Best Regards,
    Angelia

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Angelia - I couldn't get randbetween and lookupvalue to work together in the latest Power BI Desktop version but separating the two into separate columns seems to be a workaround for my issue. Thanks.

      • v-huizhn-msft's avatar
        v-huizhn-msft
        Microsoft Employee

        Hi Anonymous ,

        I am very happy for you have resolved your issue. You'd better mark the corresponding reply which will help others find the solution easily. Thank you very much.

        Best Regards,
        Angelia

  •  

    Given your list of words, here's a method that creates another list that contains 1 million items randomly selected from the initial list:

     

    let
        list = {"Apples", "Bananas", "Pears"},
        shuffle = List.Generate(
            () => 1, 
            each _ <= 1000000, 
            each _ + 1, 
            each list{Number.RoundDown(
                Number.RandomBetween(0, List.Count(list))
            )}
        )
    in
        shuffle