cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HF306
Helper I
Helper I

Random Name Generator

Hi everyone!

 

Is it possible to do a random name picker using PowerApps. The function is when user click a button, it automatically pick one name randomly as a winner. The name are extracted from Excel document. Here is a link as an example 
https://pickrandomname.com/.

 

Edit: Data is extracted from SharePoint list and it will display winner name.

 

image.PNG

 

I appreciate all feedback!

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Community Champion
Community Champion

Hi @HF306

 

Set OnSelect of the button to

Set(WinnerIs,First(
      Shuffle(IssueTracker)
).Title)

Set Text of the Label to 

WinnerIs

 

Note

IssueTracker - SPList

Title - ColumnName

Example

StalinPonnusamy_1-1631884368813.png

 

 

View solution in original post

10 REPLIES 10
Digital
Continued Contributor
Continued Contributor

Does your excel table have row numbers? If so you could you the RandBetween function to select a random number which you could then use to do a LookUp on the table.

 

OnSelect of your button

Set(varTheWinner, LookUp(ExcelTable, ID = RandBetween(1,CountRows(YourExcelTable)), Name))

 

Text box

varTheWinner

 

If your excel table isn't numbered, not to worry as you can put it into a collection then use the following code to add row numbers to your collection:

 

// set row numbers
With(
    {
        records:colExcelTable
    },
    ForAll(
        Sequence(CountRows(records)),
        Patch(
            Last(
                FirstN(records,Value)),
                {rowNumber: Value}
            )
        )
);
// pick the random winner
Set(varTheWinner, LookUp(colExcelTable, rowNumber = RandBetween(1,CountRows(colExcelTable)), Name))

 

StalinPonnusamy
Community Champion
Community Champion

Hi @HF306 

 

Insert button and Set OnSelect to 

 

 

Set(RandomNumber, Round(Rand() * 10000,0) )

 

 

Insert label on your screen and set the Text property to

 

 

RandomNumber

 

 

 

StalinPonnusamy_0-1631760480357.png

 

Note :

  • * 10000 Defines the number of digits
  • This function generates the number, using lookup we can get the data from excel using a unique ID

 

 

 

 

 

StalinPonnusamy
Community Champion
Community Champion

Hi @HF306 

 

StalinPonnusamy_1-1631760879715.png

 

timl
Super User
Super User

Hi @HF306 

To return an arbitrary record from an Excel table, you can call the Shuffle function to randomise the records, and then call the first function to retrieve the first record.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-shuffle

 

Assuming the name of your Excel table is yourExcelTable and that Firstname is the column that contains the name, this is the syntax that you would use:

First(
      Shuffle(yourExcelTable)
).Firstname

Thank you for the assist!

What about from SharePoint list? Item require are Name and ID.

 

Edit: Only 10 names are only going to be picked

Digital
Continued Contributor
Continued Contributor

I would suggest using Timl's suggestion as it is much simpler than mine.

 

 

Put your SharePoint list into a collection on Screen Visible or App OnStart

 

ClearCollect(colTheContestants,YourSharePointList)

 

 

Button OnSelect

Set(
    varTheWinner,
    First(Shuffle(colTheContestants)).Name
)

 

Label Text property

varTheWinner

 

You could put the SharePoint list directly into the Shuffle formula but it'll be a little bit slower.

I encounter an error, nameList is my SharePoint list. 

 

button.PNGonstart.PNGimage.PNG

StalinPonnusamy
Community Champion
Community Champion

Hi @HF306

 

Set OnSelect of the button to

Set(WinnerIs,First(
      Shuffle(IssueTracker)
).Title)

Set Text of the Label to 

WinnerIs

 

Note

IssueTracker - SPList

Title - ColumnName

Example

StalinPonnusamy_1-1631884368813.png

 

 

View solution in original post

StalinPonnusamy
Community Champion
Community Champion

@HF306 

 

With your Datasource

 

Set(TheWinner,First(
      Shuffle('NameLIST')
).ID)

 

NOTE: SharePoint already has a column called ID. Make sure you are using the correct column schema name

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,001)