Created
March 13, 2024 07:17
-
-
Save bjulius/e80cabe985a714bf608b7dba116e26e1 to your computer and use it in GitHub Desktop.
Excel BI Challenge 411 - 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], | |
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type), | |
Dupe = Table.DuplicateColumn(AddIndex, "Sentences", "Sentences2"), | |
SplitToRows1 = Table.ExpandListColumn(Table.TransformColumns(Dupe, {{"Sentences2", Splitter.SplitTextByDelimiter(" """, QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sentences2"), | |
SplitToRows2 = Table.ExpandListColumn(Table.TransformColumns(SplitToRows1, {{"Sentences2", Splitter.SplitTextByDelimiter(""" ", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sentences2"), | |
IdentifyAddlSplits = Table.AddColumn(SplitToRows2, "Custom", each [ | |
a = [Sentences], | |
b = Text.ToList( a ), | |
c = List.Select( b, each _ = """" ), | |
d = List.Count( c ), | |
e = if Text.StartsWith( [Sentences2], """" ) then [Sentences2] else | |
if Text.EndsWith( [Sentences2], """" ) then [Sentences2] else | |
if d = 0 then Text.Replace( [Sentences2], " ", "*") else | |
if not List.Contains( {"A".."Z"}, Text.Start( [Sentences2], 1)) then [Sentences2] else | |
Text.Replace( [Sentences2], " ", "*") | |
][e]), | |
SplitToRows3 = Table.ExpandListColumn(Table.TransformColumns(IdentifyAddlSplits, {{"Custom", Splitter.SplitTextByDelimiter("*", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom"), | |
RemCols = Table.RemoveColumns(SplitToRows3,{"Sentences2"}), | |
Group = Table.Group(RemCols, {"Sentences"}, {{"All", each _, type table [Sentences=text, Index=number, Custom=nullable text]}}), | |
AddColNo = Table.AddColumn(Group, "ColumnNo", each Table.AddIndexColumn( [All], "Column", 1, 1)), | |
RemCol2 = Table.RemoveColumns(AddColNo,{"All"}), | |
Expand = Table.ExpandTableColumn(RemCol2, "ColumnNo", {"Index", "Custom", "Column"}, {"Index", "Custom", "Column"}), | |
Pivot = Table.Pivot(Table.TransformColumnTypes(Expand, {{"Column", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(Expand, {{"Column", type text}}, "en-US")[Column]), "Column", "Custom"), | |
Sort = Table.Sort(Pivot,{{"Index", Order.Ascending}}), | |
Remove = Table.RemoveColumns(Sort,{"Index"}) | |
in | |
Remove |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment