Google Sheets – Custom Data Transpose Methods

google sheetsgoogle-apps-script

I have an export for a group that composed of student/mentors. Everyone in the group is both a student and a mentor. I need to transform the data to have mentors with assigned students rather than students with assigned mentors.

The software gives me an export such as five columns in a sheet that has student names and mentors that have been assigned to that student:

ID Numbers of Students | Students | Mentor 1 | Mentor 2 | Mentor 3

I need a sheet to reference the data with mentors in one column and corresponding students such as:

ID Numbers of Mentors | Mentors | Student 1 | Student 2 | Student 3 | Student 4

Students are mentors and mentors are students – it is the same set of names. Mentors have a max of four assigned students. Only one row per Mentor.

I am thinking QUERY() or perhaps ARRAYFORMULA() but I have not been able to assigned use VLOOKUP() or FILTER() with ARRAYFORMULA(). I am not getting anywhere with it.

What Google Spreadsheet formula do I use to transpose the data as described? Can you provide an example? I will accept a custom function, but surly this can be done with existing tools.

Best Answer

Using your example, this formula can be used in row 2:

=TRANSPOSE(FILTER(B$2:B;MMULT(C$2:E=B2;TRANSPOSE(SIGN(COLUMN(C$2:E$2))))))

but will need to be filled down as far as is required. Hopefully you can adapt the references to your actual data, but comment back if this is an issue.

MMULT Usage

If you require a single formula that will automatically populate the entire data set, this can be done with native functions, but it will be horribly complex and quite inefficient. I would suggest a custom function if a single-formula solution was a requirement.