@radley,
This is doable, but a little trickier than it seems at first glance. Here’s what I did, starting with your unpivoted data above :
-
pulled the whole string into one column called Project And Name
-
duplicated the column, and split by character transition (digit to text) to get two columns: Project Only and Name Only
-
Grouped Rows by Project Only and All Rows
-
this is where it gets a little tricky - went into advanced editor and added the following line to the M code:
{“First in List”, each List.First( [Name Only] ), type text}
In the Grouped Rows section of the code. This gives us the first name in each project
- expanded all rows
- created a conditional column called Final:
And we’re done…
Full solution file attached below, and here’s the full M code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlEwVPDKz8hTCM7NLMlQUIrVQZZxyk9SCM/MyclMzC3GkCtKTFHwSy3PScxLQZM0QjISTQK3iUBNiXmpIMkUpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Project and Name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project and Name", type text}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Project and Name", "Project and Name - Copy"),
#"Renamed Columns" = Table.RenameColumns(#"Duplicated Column",{{"Project and Name - Copy", "Name Only"}}),
#"Split Column by Character Transition" = Table.SplitColumn(#"Renamed Columns", "Name Only", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Name Only.1", "Name Only.2"}),
#"Renamed Columns1" = Table.RenameColumns(#"Split Column by Character Transition",{{"Name Only.1", "Project Only"}, {"Name Only.2", "Name Only"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns1", {"Project Only"}, {{"Ct", each Table.RowCount(_), type number}, {"AllRows", each _, type table [Project and Name=text, Project Only=text, Name Only=text]},
{"First in List", each List.First( [Name Only] ), type text}}),
#"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"Project and Name", "Project Only", "Name Only"}, {"AllRows.Project and Name", "AllRows.Project Only", "AllRows.Name Only"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded AllRows", "Final", each if [AllRows.Name Only] = [First in List] then [AllRows.Project and Name] else [AllRows.Name Only])
in
#"Added Conditional Column"
Hope this gets you what you need.