let
Source = Excel.CurrentWorkbook(){[Name="TableMain"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Bus Driver Name", type text}, {"Driver ID", Int64.Type}, {"Driver Mobile1", type text}, {"Driver Mobile2", Int64.Type}, {"Bus Number", type text}, {"Number of Seats", Int64.Type}, {"Kindergarten", type text}, {"Number of students", Int64.Type}, {"Boys School", type text}, {"Number of Students2", Int64.Type}, {"Girls School Cycle1", type text}, {"Number of Students3", Int64.Type}, {"Girls School Cycle2", type text}, {"Number of Students4", Int64.Type}, {"Girls School Cycle3", type text}, {"Number of Students5", Int64.Type}, {"Bus Monitor Kindergarten", type text}, {"Monitor ID", Int64.Type}, {"Mobile Number", Int64.Type}, {"Bus Monitor Boys School", type text}, {"Monitor ID2", Int64.Type}, {"Mobile Number2", Int64.Type}, {"Bus Monitor Girls School Cycle1", type text}, {"Monitor ID3", Int64.Type}, {"Mobile Number3", Int64.Type}, {"Bus Monitor Girls School Cycle2", type text}, {"Monitor ID4", Int64.Type}, {"Mobile Number4", Int64.Type}, {"Bus Monitor Girls School Cycle3", type text}, {"Monitor ID5", Int64.Type}, {"Mobile Number5", Int64.Type}}),
UnpivotSchools = Table.UnpivotOtherColumns(Typed, {"Bus Driver Name", "Driver ID", "Driver Mobile1", "Driver Mobile2", "Bus Number", "Number of Seats", "Number of students", "Number of Students2", "Number of Students3", "Number of Students4", "Number of Students5", "Bus Monitor Kindergarten", "Monitor ID", "Mobile Number", "Bus Monitor Boys School", "Monitor ID2", "Mobile Number2", "Bus Monitor Girls School Cycle1", "Monitor ID3", "Mobile Number3", "Bus Monitor Girls School Cycle2", "Monitor ID4", "Mobile Number4", "Bus Monitor Girls School Cycle3", "Monitor ID5", "Mobile Number5"}, "School Type", "School Name"),
OtherData = Table.AddColumn(UnpivotSchools, "Custom", each if [School Type]= "Kindergarten" then [Number of Students = [Number of students], Monitor Name = [Bus Monitor Kindergarten], Monitor ID = [Monitor ID], Monitor Mobile Number = [Mobile Number]] else
if [School Type] = "Boys School" then [Number of Students = [Number of Students2], Monitor Name = [Bus Monitor Boys School], Monitor ID = [Monitor ID2], Monitor Mobile Number = [Mobile Number2]] else
if [School Type] = "Girls School Cycle1" then [Number of Students = [Number of Students3], Monitor Name = [Bus Monitor Girls School Cycle1], Monitor ID = [Monitor ID3], Monitor Mobile Number = [Mobile Number3]] else
if [School Type] = "Girls School Cycle2" then [Number of Students = [Number of Students4], Monitor Name = [Bus Monitor Girls School Cycle2], Monitor ID = [Monitor ID4], Monitor Mobile Number = [Mobile Number4]] else
[Number of Students = [Number of Students5], Monitor Name = [Bus Monitor Girls School Cycle3], Monitor ID = [Monitor ID5], Monitor Mobile Number = [Mobile Number5]]),
ColumnsRemoved = Table.SelectColumns(OtherData,{"Bus Driver Name", "Driver ID", "Driver Mobile1", "Driver Mobile2", "Bus Number", "Number of Seats", "School Type", "School Name", "Custom"}),
CustomExpanded = Table.ExpandRecordColumn(ColumnsRemoved, "Custom", {"Number of Students", "Monitor Name", "Monitor ID", "Monitor Mobile Number"}, {"Number of Students", "Monitor Name", "Monitor ID", "Monitor Mobile Number"})
in
CustomExpanded