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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 464

#2
Haque Profile Picture

Haque 431

#3
David_MA Profile Picture

David_MA 323 Super User 2026 Season 1

Last 30 days Overall leaderboard