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

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Need help writing a formula/code snippet

(0) ShareShare
ReportReport
Posted on by 501

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! 

I have the same question (0)
  • Verified answer
    Expiscornovus Profile Picture
    32,820 Most Valuable Professional on at
    Re: Need help writing a formula/code snippet

    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,274 Super User 2025 Season 2 on at
    Re: Need help writing a formula/code snippet

    @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
    32,820 Most Valuable Professional on at
    Re: Need help writing a formula/code snippet

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 797 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 425 Moderator

#3
developerAJ Profile Picture

developerAJ 319

Last 30 days Overall leaderboard