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 Platform Community / Forums / Power Automate / Need help writing a fo...
Power Automate
Answered

Need help writing a formula/code snippet

(0) ShareShare
ReportReport
Posted on by 503

Hi all 

 

I am creating a flow and its currently getting the first user record based on a list of users/records. 

 

Here is the compose snippet which currently gets the first user id from the list: 

first(outputs('List_rows')?['body']?['value'])?['systemuserid']

 

What I would like to do now is change this snippet so that it gets the records in the list at random and not be the first record all the time.

I have tried using the rand function many different ways but cant get it right. 

Does anyone know how to write it correctly? I would really appreciate it!

Thanks in advance all! 

Categories:
  • Verified answer
    Expiscornovus Profile Picture
    33,997 Most Valuable Professional on at

    Hi @Usernametwice23,

     

    You could combine a rand function with the length of the array and use a skip and a first to get a random item.

     

    Try something like below:

     

    first(skip(outputs('List_rows')?['body']?['value'], rand(0,length(outputs('List_rows')?['body']?['value']))))?['systemuserid']

     

  • RobElliott Profile Picture
    10,539 Super User 2026 Season 2 on at

    @Usernametwice23 I have a flow that gets 1 random country each day from a SharePoint list for our intranet. The compose action has the following expression:

     

    body('Get_items')?['value'][rand(1,length(body('Get_items')?['value']))]

     

    randomCountry.png

     

    Rob
    Los Gallardos
    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

  • Expiscornovus Profile Picture
    33,997 Most Valuable Professional on at

    Hi @RobElliott,

     

    Great to see that also works, that looks a lot simpler compared to what I suggested 😁

     

    Only suggestion I would have would be to start the range with the 0. Otherwise the first country record will always be ignored from the random pick 😉

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 349 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard