Created
September 12, 2022 04:33
-
-
Save bjulius/096adc77f4a3cbb2cec55a1a8aa9f0c5 to your computer and use it in GitHub Desktop.
Solution to Excel BI Excel/Power Query Challenge 19
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 = #"Sentences Raw", | |
AddedIndex = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type), | |
SplitBySpaces = Table.ExpandListColumn(Table.TransformColumns(AddedIndex, {{"Sentence", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sentence"), | |
TrimmedText = Table.TransformColumns(SplitBySpaces,{{"Sentence", Text.Trim, type text}}), | |
WordLength = Table.AddColumn(TrimmedText, "WordLength", each Text.Length( [Sentence] )), | |
MaxLengthBySentence = Table.Group(WordLength, {"Index"}, {{"AllData", each _, type table [Sentence=text, Index=number, WordLength=number]}, {"MaxLength", each List.Max([WordLength]), type number}}), | |
ExpandedAllData = Table.ExpandTableColumn(MaxLengthBySentence, "AllData", {"Sentence", "WordLength"}, {"Sentence", "WordLength"}), | |
AddedLengthEqMaxLen = Table.AddColumn(ExpandedAllData, "LengthEqMaxLen", each if [WordLength] = [MaxLength] then 1 else 0), | |
FilteredToMaxLenWords = Table.RemoveColumns( Table.SelectRows(AddedLengthEqMaxLen, each ([LengthEqMaxLen] = 1)), {"WordLength", "MaxLength", "LengthEqMaxLen"}), | |
CapitalizedWords = Table.TransformColumns(FilteredToMaxLenWords,{{"Sentence", Text.Proper, type text}}), | |
GroupedRows = Table.Group(CapitalizedWords, {"Index"}, {{"AllData", each _, type table [Index=number, Sentence=text]}}), | |
#"Extracted&Cleanup" = Table.RemoveColumns( Table.AddColumn(GroupedRows, "Expected Answer", each Text.Combine( [AllData][Sentence], ", ")), {"Index", "AllData"}) | |
in | |
#"Extracted&Cleanup" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment