Skip to content

Instantly share code, notes, and snippets.

@bjulius
Created April 23, 2023 08:04
Show Gist options
  • Save bjulius/604baaa0194a0cac8c8a7819977e4ccc to your computer and use it in GitHub Desktop.
Save bjulius/604baaa0194a0cac8c8a7819977e4ccc to your computer and use it in GitHub Desktop.
Excel BI Excel Challenge 177 - Brian Julius Solution
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Dupe1'" = Table.DuplicateColumn(Source, "Number1", "Number1Digits"),
ReType1 = Table.TransformColumnTypes(#"Dupe1'",{{"Number1Digits", type text}}),
ToList1 = Table.AddColumn(ReType1, "Digits1", each Text.ToList( [Number1Digits] )),
Expand1 = Table.ExpandListColumn(ToList1, "Digits1"),
Group1 = Table.Group(Expand1, {"Number1", "Number2", "Digits1"}, {{"Count1", each Table.RowCount(_), Int64.Type}}),
Dupe2 = Table.DuplicateColumn(Source, "Number2", "Number2Digits"),
ReType2 = Table.TransformColumnTypes(Dupe2,{{"Number2Digits", type text}}),
ToList2 = Table.AddColumn(ReType2, "Digits2", each Text.ToList( [Number2Digits] )),
Expand2 = Table.ExpandListColumn(ToList2, "Digits2"),
Group2 = Table.Group(Expand2, {"Number1", "Number2", "Digits2"}, {{"Count2", each Table.RowCount(_), Int64.Type}}),
Rename = Table.RenameColumns(Group2,{{"Number1", "Number01"}, {"Number2", "Number02"}}),
Join = Table.Join( Group1, {"Number1", "Digits1"}, Rename, {"Number01", "Digits2"}, JoinKind.LeftOuter),
Custom1 = Table.SelectRows(Join, each [Count1] = [Count2]),
RemCols = Table.SelectColumns(Custom1,{"Number01", "Digits1"}),
Group3 = Table.Group(RemCols, {"Number01"}, {"All", each List.Sort( [Digits1])}),
Extract = Table.TransformColumns(Group3, {"All", each Text.Combine(List.Transform(_, Text.From), ", "), type text}),
Final = Table.RenameColumns( Table.RemoveColumns( Table.Join(Source, "Number1", Extract, "Number01", JoinKind.LeftOuter), "Number01"), {"All", "Answer"})
in
Final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment