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
    )
  )
)

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,215)