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
Super User
Super User

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
Super User
Super User

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
Super User
Super User

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
Super User
Super User

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

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
Super User
Super User

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

 

 

StalinPonnusamy
Super User
Super User

@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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,270)