cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cbernier35
Helper I
Helper I

Return 3 random results from SharePoint online list

Does anyone know how to return 3 random results to a gallery from SharePoint online list?
1 ACCEPTED SOLUTION

Accepted Solutions

The works, however it's the order that matters:

 

ClearCollect(
    GalleryCollection,
    FirstN(
        Shuffle(
            Filter(
                'SharePoint Online List',
                IsBlank(Selector1.Selected.Result) Or SPOListColumnA = Selector1.SelectedText.Value,
                IsBlank(ComboBox1.Selected.Result) Or SPOListColumnB = ComboBox1.Selected.Result,
                IsBlank(ComboBox2.Selected.Result) Or SPOListColumnC = ComboBox2.Selected.Result,
        ),
        3
    )
  )
)

View solution in original post

5 REPLIES 5
CarlosFigueira
Power Apps
Power Apps

You can set the Items property of the gallery to the following expression:

FirstN(Shuffle(YourSharePointList), 3)

That will first Shuffle the items of the list (notice that it doesn't modify the list itself, the shuffle is done with the items in memory), then takes 3 of those elements.

Hope this helps!

Hi, that seems to work, however sometimes it shows one result, sometimes no results, sometimes two, sometimes three.  Is there a way to always return random three results if available?

@CarlosFigueiraany idea about the question above?

Hi @cbernier35 ,

I'm afraid there's no function about returning a specific number of random records in PowerApps.

As an alternative, since Shuffle() function will return at least one record every time, I suggest you collect its data for three times.

Then the result table's record number must be larger than three.

Try this:

1)set the screen's OnVisible:

ClearCollect(test,Shuffle(datasource));Collect(test,Shuffle(datasource));Collect(test,Shuffle(datasource))

2)set the gallery's Items:

FirstN(test,3)

 

 

 

Best regards,

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

The works, however it's the order that matters:

 

ClearCollect(
    GalleryCollection,
    FirstN(
        Shuffle(
            Filter(
                'SharePoint Online List',
                IsBlank(Selector1.Selected.Result) Or SPOListColumnA = Selector1.SelectedText.Value,
                IsBlank(ComboBox1.Selected.Result) Or SPOListColumnB = ComboBox1.Selected.Result,
                IsBlank(ComboBox2.Selected.Result) Or SPOListColumnC = ComboBox2.Selected.Result,
        ),
        3
    )
  )
)

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,082)