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

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:
I have the same question (0)
  • Verified answer
    Expiscornovus Profile Picture
    33,175 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,313 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
    33,175 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard