Created
November 30, 2022 10:07
-
-
Save bjulius/f9b139310d606daad51da8728d66ecd9 to your computer and use it in GitHub Desktop.
Excel BI Challenge 76 - 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 = NewcomersRaw, | |
ReplaceAnd = Table.ReplaceValue(Source,"and",",",Replacer.ReplaceText,{"The Newcomers"}), | |
Split = Table.SplitColumn(ReplaceAnd, "The Newcomers", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv)), | |
Unpivot = Table.UnpivotOtherColumns(Split, {"Year"}, "Attribute", "Value"), | |
Trim = Table.TransformColumns(Unpivot,{{"Attribute", Text.Trim, type text}, {"Value", Text.Trim, type text}}), | |
Filter = Table.SelectRows(Trim, each ([Value] <> "" and [Value] <> "s" and [Value] <> "Tobago" and [Value] <> "Herzogovenia" and [Value] <> "the Grenadines" and [Value] <> "Principe" and [Value] <> "Nevis")), | |
FirstLetter = Table.SplitColumn(Filter, "Value", Splitter.SplitTextByPositions({0, 1}, false), {"Alphabet", "Value.2"}), | |
Group = Table.Group(FirstLetter, {"Alphabet"}, {{"Count", each Table.RowCount(_), Int64.Type}}), | |
Rank = Table.AddRankColumn( Group, "Rank", {"Count", Order.Descending}, [RankKind = RankKind.Dense] ), | |
FilterNClean = Table.RemoveColumns( Table.SelectRows(Rank, each [Rank] <= 3), "Rank") | |
in | |
FilterNClean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks simple, but absolutely wicked curveball in this one - filter step needs to include all countries with " and " in the name to avoid counting as two countries:
Filter = Table.SelectRows(Trim, each ([Value] <> "" and [Value] <> "s" and [Value] <> "Tobago" and [Value] <> "Herzogovenia" and [Value] <> "the Grenadines" and [Value] <> "Principe" and [Value] <> "Nevis"))