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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Flow to Randomly Pair ...
Power Automate
Unanswered

Flow to Randomly Pair Items from Two Different Lists

(0) ShareShare
ReportReport
Posted on by

I have the following two lists either in SharePoint or Excel:

 

List 1:  FirstName, LastName, Email

List 2:  SeatNumber (A1, A2, A3, B1, B2, B3, etc.)

 

The first is a listing of students.  The second is a listing of seat number in our classroom.  I would like to create a flow that randomly pairs a Seat Number from List 2 to a Student in List 1 and produces a list of each student's seat assignment for the day.

 

What strategy would I use to accomplish this with Power Automate?

 

Categories:
I have the same question (0)
  • GeoffRen Profile Picture
    Microsoft Employee on at

    You can use Office Scripts, specifically Office Scripts with Power Automate. This is the 'Run Script' action on the Excel connector. With Office Scripts you can use the 'Run Script' action to execute javascript against a workbook. So you can get the info from the Excel workbook then use the `Math.random()` function to help you pair the lists together randomly. Finally, you can write the assignments back to Excel, all in the same script.

     

    I don't know what format your data is held in or where you want it written/sent to, so here's a basic script that can do this. In your flow, you'll need to pass in two parameters: a list of students (just a string array here), and the list of seat numbers (also an array of strings). It'll return an array of student to seat mappings, ex [{ student: 'Bob', seat: 'a5' }, { student: 'Josh', seat: 'b4' }]

     

     

    function main(workbook: ExcelScript.Workbook, students: string[], seats: string[]): { student: string; assignment: string }[] {
     const assignments = [];
     for (let i = 0; i < students.length; i++) {
     const randomSeat = Math.floor(Math.random() * Math.floor(seats.length));
     assignments.push({ student: students[i], assignment: seats[randomSeat] });
     seats.splice(randomSeat, 1);
     }
    
     return assignments;
    }

     

     

  • ggoodfellow Profile Picture
    on at

    Many thanks!  I will see if I can get that to work.  I'm new to Javascript but willing to learn.

  • mahoneypat Profile Picture
    1,720 on at

    Please see this post by Ed Gonzales in this previously solved post.  It is very close to what you are describing.

     

    Solved: Anyone good with Array, SharePoint Lists and Rando... - Power Platform Community (microsoft.com)

     

    Regards,

    Pat

  • ggoodfellow Profile Picture
    on at

    Many thanks for the linked post.  It is nice to see several options to complete something similar.

  • Robert94 Profile Picture
    520 on at

    Hi,
    I have the same project and I can`t get it to work, would it be possible for you if you`d attach some pics with the flow?

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard