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.
I appreciate all feedback!
Solved! Go to Solution.
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
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))
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
Note :
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.
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
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
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
187 | |
52 | |
51 | |
35 | |
33 |
User | Count |
---|---|
265 | |
97 | |
84 | |
77 | |
74 |