cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ENRM
Helper III
Helper III

Draw random numbers

Hello everyone.
I have three text input boxes, where the boxes are defined as numbers. There are "min" numbers, "max" numbers and "quantity" numbers. When I press the random button, I create a table, with numbers from the text input boxes "min" and "max". Then I draw a random "quantity it is displayed in a gallery.

Then comes the question.
I want to press the random button once and the first random number should appear in a Label on the screen. Then I should be able to press the next button and the next number will appear in Label, and previous numbers will be shown in the gallery. Is this possible to achieve in a decent and simple way?
Attaches coding to the Random button. The formula is in the Norwegian setup of power apps. A comma becomes a semicolon and a semicolon becomes a double semicolon.

 

 

 

Skjermbilde 2023-03-09 192709.png

Skjermbilde 2023-03-09 192622.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
TheRobRush
Super User
Super User

OOOOOOOH OK Makes sense. Ok so Single number box 

Last(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers))

mulitbox below it 

Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers-1), Value, " ")

 

then you can add a little to that all numbers box to show when all numbers have drawn say like 

Switch(winningNumbers,
       Value(TextInput3.Text),
       Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers), Value, " "),
       Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers-1), Value, " ")
)

 

and even set visible of the solo number box to 

Switch(winningNumbers,
       Value(TextInput3.Text), false, true)

 

adding in those last two will make it display one at a time and then move into the group as you continue until the end, at which point all numbers will show in the group box

 

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

TheRobRush
Super User
Super User

watched your vide, looks lovely. Reason it just goes straight to the box below is the last part we added.

Switch(winningNumbers,
       Value(TextInput3.Text), false, true)

change visible of the single text box from that, to true, and it will stay there 😉

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

View solution in original post

15 REPLIES 15
TheRobRush
Super User
Super User

Where I have 3 text inputs, set to numbers, named TextInput 1 2 3, in my buttons onselect I place

 

ClearCollect(numbersDraw, 
             ForAll(Sequence(Sum(TextInput2.Text+1-TextInput1.Text),TextInput1,1) As numberTurn, {Value:numberTurn.Value, Random:Rand()}))

 

 

In my label I place

 

Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), TextInput3.Text), Value, " ")

 

 

TheRobRush_0-1678392061089.png

 

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

@TheRobRush 

My formula works on the random button, but I want to add a new next button.

I want to press the random button once and the first random number should appear in a Label on the screen. Then I should be able to press the next button and the next number will appear in Label, and previous numbers will be shown in the gallery. 

The ultimate would be that now that the last number has been drawn, a text will appear saying "No more moves"

@ENRM 

 

If I understood correctly, you want to 

 

1) Press Random once > then Next once (?) > then a text saying "No more moves"

2) Display the current value in a label, and the previous in a gallery

 

You can use a variable to capture the button presses.  Add something like this to the "OnSelect" for your Random and Next buttons:

UpdateContext({varButtonPush: varButtonPush + 1})

 

You can then reference this for your buttons in the DisplayMode property.  For example, for the "Random" button you can add:

If(varButtonPush > 0, DisplayMode.Disabled)

 

So you can disable your buttons as the user advances. For the "No More Moves", you can set the visible property to 

If(varButtonPush = 2,true,false)

 

For the Gallery portion, you can capture the previous value into a collection, and then use that for your Gallery.   So if the current value is in your label, before you replace that with a new value, add this to the beginning of your formula:

Collect(colPriorRandom,YourTextLabel.Text)

Rusk_0-1678395148719.png

 

You'll want to clear the collection at some point, but these are just a few ideas that may work for your use case

 

TheRobRush
Super User
Super User

So, I would still make your random button different, as yours is far more complex than necessary and will make future edits harder if someone that isn't you has to work with this code one day.

 

To test, make a button with the onselect of

If(IsBlank(winningNumbers),
ClearCollect(numbersDraw, 
ForAll(Sequence(Sum(TextInput2.Text+1-TextInput1.Text),TextInput1,1) As numberTurn, {Value:numberTurn.Value, Random:Rand()})));

Set(winningNumbers, If(IsBlank(winningNumbers),1, winningNumbers+1))

 

and set its displaymode to

If(Not(winningNumbers=Value(TextInput3.Text)), DisplayMode.Edit, DisplayMode.Disabled)

 

and it's text to

If(Not(winningNumbers=Value(TextInput3.Text)), "Draw Number", "Draw Complete")

 

then put a label in the screen with this text

Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers), Value, " ")

 

this will draw one number at a time until the requested limit is reached, then chaneg your button from draw number to draw complete and make it unable to be pressed further. Can then reset it by placing this somewhere, if needed

Set(winningNumbers,Blank())

 

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

@TheRobRush 

Entered what you wrote and got this? Unable to press.

 

ENRM_0-1678398094654.png

 

TheRobRush
Super User
Super User

Check your display mode of the button and make.sure you changed the textbox3 reference to name of your own textbox where your draw count is located. And if it is correct then place a label somewhere and see what value is currently in winningNumbers (also check that all my formula textbox references where swapped when you put them.in your app so you dont end up with a reference throwing it off 🙂 )

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

@TheRobRush 

Typo on the text box. Thanks. This works well.
What if I want to show only one feature in a new text box, and that all are collected in the one I have now.

TheRobRush
Super User
Super User

Do you mean you want a seperate text box for each number revealed by the draw?

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

@TheRobRush 

No, not separately. A textbox. The first number appears in and the next number appears in the same text box and the first goes into the text box that is there now. If this makes sense

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Top Solution Authors
Top Kudoed Authors
Users online (3,849)