web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Unanswered

Random Variable

(0) ShareShare
ReportReport
Posted on by 52

Hi,

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

Thank you!

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @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.

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    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,

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @v-xida-msft 

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

  • Haufe Profile Picture
    52 on at

    Hi 

     

    Thank so much for your answer.

     

     

     

    Data Table

    Items = RandomRecord

     

    Button

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

     

     

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    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,

  • Haufe Profile Picture
    52 on at

    Hi 

     

    Follow the screenshot like you request:

    Button.PNGDataTable.PNG

     

    Best regards,

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    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 Power Platform Member Profile Picture
    Microsoft Employee on at

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

     

    Thank you.,

     

    @Anonymous 

  • Haufe Profile Picture
    52 on at

    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,

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Haufe 

    As a test, try changing your Items property on the DataTable to 'Table2'. Does it display any data?

    If it does, then chage it back to your collection and add a Label to your screen with the Text Property of that Label set to : CountRows(Coleção1)

    That lable should show when you click on your button...what does it show and what is the result of the first test?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 429 Most Valuable Professional

#2
11manish Profile Picture

11manish 191 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 122 Super User 2026 Season 2

Last 30 days Overall leaderboard