Created
February 12, 2023 15:33
-
-
Save bjulius/52f74c7229e2684923358ae7854c2de6 to your computer and use it in GitHub Desktop.
Excel BI Excel/Power Query Challenge 127 - Brian Julius Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], | |
AddToList = Table.RemoveColumns( Table.DuplicateColumn( Table.AddColumn(Source, "StripList", each Text.ToList([LSTRIP Chars])), "Input String", "OriginalString"), "LSTRIP Chars"), | |
AddOrigToList = Table.AddColumn(AddToList, "OrigToList", each Text.ToList([OriginalString] )), | |
Expand = Table.ExpandListColumn(AddOrigToList, "OrigToList"), | |
AddInStriplist = Table.AddColumn(Expand, "InStripList", each if List.Contains( [StripList], [OrigToList]) then "Strip" else "Keep"), | |
Remove = Table.SelectColumns(AddInStriplist,{"InStripList", "Input String"}), | |
Reorder = Table.ReorderColumns(Remove,{"Input String", "InStripList"}), | |
GroupKindLocal = Table.Group(Reorder, {"Input String", "InStripList"}, {{"Remove", each Table.RowCount(_), Int64.Type}}, GroupKind.Local), | |
Regroup = Table.Group(GroupKindLocal, {"Input String"}, {{"All", each _, type table [Input String=text, InStripList=text, Remove=number]}}), | |
AddIndex = Table.RemoveColumns( Table.AddColumn(Regroup, "Custom", each Table.AddIndexColumn( [All], "Index", 1, 1)), "All"), | |
ExpandNFilter = Table.RemoveColumns( Table.SelectRows( Table.ExpandTableColumn(AddIndex, "Custom", {"InStripList", "Remove", "Index"}, {"InStripList", "Remove", "Index"}), each [Index] = 1), "Index"), | |
RangeRemove = Table.AddColumn(ExpandNFilter, "Result", each if [InStripList] = "Keep" then [Input String] else Text.RemoveRange( [Input String], 0, [Remove] )), | |
Clean = Table.RemoveColumns(RangeRemove,{"InStripList", "Remove"}) | |
in | |
Clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment