let
Source = Excel.Workbook(File.Contents("\\PRO01\RDSdesktop$\cin\Desktop\Dataplatform og BI\Rune\2022-03-02-grundvandsanalyser (4).xlsx"), null, true),
Sheet0_Sheet = Source{[Item="Sheet0",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet0_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"BOREHOLENO", type text}, {"KOMMUNE", type text}, {"BOR_ANVENDELSE", type text}, {"ANLAEGID", Int64.Type}, {"INDTNR", Int64.Type}, {"GRUMO_NR", type any}, {"XUTM32EUREF89", Int64.Type}, {"YUTM32EUREF89", Int64.Type}, {"PROEVEID", Int64.Type}, {"PROEVEDATO", type date}, {"STOFGRUPPE_KODE", Int64.Type}, {"STOFNR", Int64.Type}, {"MAENGDE", type number}, {"ATTRIBUT", type text}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"ID", "BOREHOLENO", "KOMMUNE", "BOR_ANVENDELSE", "ANLAEGID", "INDTNR", "GRUMO_NR", "XUTM32EUREF89", "YUTM32EUREF89", "PROEVEID", "STOFGRUPPE_KODE"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"STOFNR", "PROEVEDATO", "MAENGDE", "ATTRIBUT"}),
#"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"STOFNR", Order.Ascending}}),
tbl = Table.Group(Source, {"STOFNR"}, {{"All", each _}}),
tbl1 = Table.TransformColumns(tbl, {{"All", each Table.FromRows(Table.ToColumns(_))}}),
max = List.Accumulate(tbl1[All], 0, (s,c)=> let tcc = Table.ColumnCount(c) in if tcc>s then tcc else s),
tcn = List.Accumulate({1..max}, {}, (s,c)=> s & {"Column" & Number.ToText(c)}),
tbl2 = Table.ExpandTableColumn(tbl1, "All", tcn),
Result = Table.RemoveColumns(tbl2,{"STOFNR"})
in
Result