let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type2" = Table.TransformColumnTypes(Source,{{"Driver Name", type text}, {"Driver ID", type any}, {"Driver Mobile", type text}, {"Driver Mobile2", Int64.Type}, {"Total Trips", Int64.Type}, {"Designation", type text}, {"Work Area", type text}, {"Bus Number", type text}, {"Bus Brand", type text}, {"Capacity", Int64.Type}, {"Bus Type", type text}, {"Kindergarten", type text}, {"residence", type any}, {"Total Students", Int64.Type}, {"points", type any}, {"start date", type any}, {"Boys School", type text}, {"residence1", type text}, {"Total Students4", Int64.Type}, {"points5", type any}, {"start date5", type datetime}, {"Girls School Cycle1", type text}, {"residence.", type text}, {"Total Students.", Int64.Type}, {"points2", type any}, {"Start Date2", type any}, {"Girls School Cycle2", type text}, {"residence2", type text}, {"Total Students2", Int64.Type}, {"Points3", type any}, {"Start Date3", type any}, {"Girls School Cycle3", type text}, {"Residence3", type text}, {"Total Students3", Int64.Type}, {"points4", type any}, {"Start Date4", type any}, {"Assistant", type any}, {"Assistant ID", type any}, {"Mobile", type any}, {"Assistant Boys", type any}, {"Assistant ID2", type any}, {"Mobile2", type any}, {"Assistant Girls1", type any}, {"Assistant ID3", type any}, {"Mobile3", type any}, {"Assistant Girls2", type any}, {"Assistant ID4", type any}, {"Mobile4", type any}, {"Assistant Girls3", type any}, {"Assistant ID5", type any}, {"Mobile5", type any}, {"Column1", type any}, {"#1", type text}, {"#2", type text}, {"#3", Int64.Type}, {"#4", type text}, {"#5", type text}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type2",{"Driver Name", "Driver ID", "Bus Number", "Capacity", "Kindergarten", "Total Students", "Boys School", "Total Students4", "Girls School Cycle1", "Total Students.", "Girls School Cycle2", "Total Students2", "Girls School Cycle3", "Total Students3"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Other Columns",{{"Total Students", "Kindergarten Students"}, {"Total Students4", "Boys School Students"}, {"Total Students.", "Girls School Cycle1 Students"}, {"Total Students2", "Girls School Cycle2 Students"}, {"Total Students3", "Girls School Cycle3 Students"}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Renamed Columns1", {"Driver Name", "Driver ID", "Bus Number", "Capacity"}, "Attribute", "Value"),
#"Duplicated Column" = Table.DuplicateColumn(#"Unpivoted Columns", "Attribute", "Attribute - Copy"),
#"Replaced Value" = Table.ReplaceValue(#"Duplicated Column"," Students","",Replacer.ReplaceText,{"Attribute - Copy"}),
#"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"Attribute - Copy", "St_Types"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"Driver ID", "St_Types"}, {{"Gr", each if Table.RowCount(Table.FillDown(Table.AddColumn(_, "Fill_Down", each if Value.Is([Value], type number) then null else [Value]),{"Fill_Down"}))=2 then Table.RemoveFirstN(Table.FillDown(Table.AddColumn(_, "Fill_Down", each if Value.Is([Value], type number) then null else [Value]),{"Fill_Down"}),1) else Table.FillDown(Table.AddColumn(_, "Fill_Down", each if Value.Is([Value], type number) then null else [Value]),{"Fill_Down"}) , type table}}),
#"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"Driver ID"}),
#"Expanded Gr" = Table.ExpandTableColumn(#"Removed Columns", "Gr", {"Attribute", "Bus Capacity", "Bus Number", "Driver ID", "Driver Name", "Fill_Down", "St_Types", "Value"}, {"Attribute", "Bus Capacity", "Bus Number", "Driver ID", "Driver Name", "Fill_Down", "St_Types.1", "Value"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Gr",{"St_Types.1"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"Driver Name", "Driver ID", "Bus Number", "Bus Capacity", "St_Types", "Fill_Down", "Value"}),
#"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Value", Int64.Type}}),
#"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type", {{"Value", null}}),
Finish = Table.RenameColumns(#"Replaced Errors",{{"St_Types", "Student_Type"}, {"Fill_Down", "Student_Name"}, {"Value", "Total_Student"}})
in
Finish