cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Haufe
Level: Powered On

Random Variable

Hi,

I need that when the user press the button, the app show one aleatory line of the my Excel. 

Thank you!

10 REPLIES 10
Super User
Super User

Re: Random Variable

@Haufe 

 

You will need to incorporate the Rand function to do this.

 

You can use a Formula such as this:

Last(
FirstN(
yourDataSource, RoundDown(Rand() * (CountRows(yourDataSource) +1) + 1, 0)
)
)

I hope this is helpful and gets you to the next step.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Community Support Team
Community Support Team

Re: Random Variable

Hi @Haufe ,

Do you want to display one Random row of your Excel table within your app when you press the button?

 

Based on the needs that you mentioned, I think the Shuffle function and First function could achieve your needs. The Shuffle function used to randomly reorder the records of a table.

Please take a try with the following formula within your app:

First(Shuffle('YourExcelTable'))

On your side, please take a try with the following workaround:

Set the OnSelect property of the Button to following:

ClearCollect(RandomRecord, First(Shuffle('YourExcelTable')))

Add a Data table control, set the Items property to following:

RandomRecord

 

More details about Shuffle function and First function, please check the following article:

Shuffle function, First function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: Random Variable

@v-xida-msft 

Now there's a function I had forgotten about...Shuffle!  Good one.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Haufe
Level: Powered On

Re: Random Variable

Hi 

 

Thank so much for your answer.

 

 

 

Data Table

Items = RandomRecord

 

Button

OnSelect = ClearCollect(RandomRecord; First(Shuffle(Table1)))

 

 

Community Support Team
Community Support Team

Re: Random Variable

Hi @Haufe ,

Could you please share a screenshot about your issue?

I have made a test on my side, and don't have the issue that you mentioned. The screenshot as below:1.JPG

 

2.JPG

 

Please check if you have enabled proper fields to display within the right Data Fields panel (as the first screenshot mentioned).

More details about enabling display fields in Data Table control within Fields panel, please check the following GIF screenshot:Test.gif

If you have solved your problem, please go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Haufe
Level: Powered On

Re: Random Variable

Hi 

 

Follow the screenshot like you request:

Button.PNGDataTable.PNG

 

Best regards,

Community Support Team
Community Support Team

Re: Random Variable

Hi @Haufe ,

I could not reproduce your issue on my side. Please check if the Collection1 that you initialized in your app is populated with proper values after you click the Button.

 

Please go to File-> Collections, then check if the Collection1 variable that you initialized within your app is populated with proper values. If not, please consider re-create a new connection to your Table data source, then try your formula again, check if the issue is solved.

 

In addition, please consider take a try to add a Label control in your app, set the Text property to following:

Collection1.RE

check if Label could display proper value.

You could also consider use Gallery to display your record instead of using Data Table control. The screenshot as below:1.JPG

On your side, please set the Items property of the Gallery to following:

Collection1

 

If the issue still exists, please consider take a try to re-create a new app, try your formula again, check if the issue still exists.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Administrator
Administrator

Re: Random Variable

Hi @Haufe can you review the latest reply and update the thread when you have a chance? 

 

Thank you.,

 

@TopShelf-MSFT 

Haufe
Level: Powered On

Re: Random Variable

Hi 


Unfortunately does not work, i did everything like told me.

 

I created another app, update my conection with the table, and saw about the collection, but the same thing Smiley Sad.


Best regards,

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 217 members 5,953 guests
Recent signins:
Please welcome our newest community members: