Created
March 7, 2023 05:02
-
-
Save bjulius/67769c07c65ffc37be64dfe560ffe8b8 to your computer and use it in GitHub Desktop.
Excel BI Excel/Power Query Challenge 145 - 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( [RSTRIP Chars])), "Input String", "OriginalString"), "RSTRIP Chars"), | |
AddOrigToList = Table.AddColumn(AddToList, "OrigToList", each Text.ToList( Text.Reverse( [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.Reverse( Text.RemoveRange( Text.Reverse( [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