Forum Discussion
AndrewPF
4 years agoHelper V
rolling up data without a parent / child reference table
If I have the following data:
| Name |
| Mainwaring group |
| Wilson |
| Jones |
| Frazer |
| Walker |
| Godfrey |
| Pike |
| Klopp group |
| Salah |
| Mane |
| Firmino |
| Milner |
| Chaucer group |
| Knight |
| Yoeman |
| Priest |
| Monk |
and I need to create another column so that I have instead:
| Name | Group |
| Mainwaring group | Mainwaring |
| Wilson | Mainwaring |
| Jones | Mainwaring |
| Frazer | Mainwaring |
| Walker | Mainwaring |
| Godfrey | Mainwaring |
| Pike | Mainwaring |
| Klopp group | Klopp |
| Salah | Klopp |
| Mane | Klopp |
| Firmino | Klopp |
| Milner | Klopp |
| Chaucer group | Chaucer |
| Knight | Chaucer |
| Yoeman | Chaucer |
| Priest | Chaucer |
| Monk | Chaucer |
How can I do it?
NB/ I have no parent / child reference table.
Try this in Power Query. Here's the concept:
1. Add a column that determines if "group" is in the Name column.
2. Add a column that returns the group name if the row is a header row.
3. Use the Fill Down feature to copy the group name to each row.
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "Tc7NCsIwDAfwVxk9+xbCBEdh4EGk9BA0tqFdUtIN0acX2h12++XrT5wzFog/oMRhCCpbMf7kzJ1yFW68CmNtGhV+qH0OOe28yOut+B1aMVPChilLKYfAG2SITRa4r4ykC7H0JmXe884Rtifq4XZiCnFtfAgu0P+albD2rhVOxvs/", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t] ), ChangeType = Table.TransformColumnTypes(Source, {{"Name", type text}}), AddIsGroup = Table.AddColumn( ChangeType, "Is Group", each if Text.PositionOf([Name], "group") = - 1 then 0 else 1 ), AddGroupName = Table.AddColumn( AddIsGroup, "Group Name", each if [Is Group] = 0 then null else [Name] ), ReplaceValue = Table.ReplaceValue( AddGroupName, " group", "", Replacer.ReplaceText, {"Group Name"} ), FillDown = Table.FillDown(ReplaceValue, {"Group Name"}), RemoveColumns = Table.RemoveColumns(FillDown, {"Is Group"}) in RemoveColumns
1 Reply
- DataInsightsSuper User
Try this in Power Query. Here's the concept:
1. Add a column that determines if "group" is in the Name column.
2. Add a column that returns the group name if the row is a header row.
3. Use the Fill Down feature to copy the group name to each row.
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "Tc7NCsIwDAfwVxk9+xbCBEdh4EGk9BA0tqFdUtIN0acX2h12++XrT5wzFog/oMRhCCpbMf7kzJ1yFW68CmNtGhV+qH0OOe28yOut+B1aMVPChilLKYfAG2SITRa4r4ykC7H0JmXe884Rtifq4XZiCnFtfAgu0P+albD2rhVOxvs/", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t] ), ChangeType = Table.TransformColumnTypes(Source, {{"Name", type text}}), AddIsGroup = Table.AddColumn( ChangeType, "Is Group", each if Text.PositionOf([Name], "group") = - 1 then 0 else 1 ), AddGroupName = Table.AddColumn( AddIsGroup, "Group Name", each if [Is Group] = 0 then null else [Name] ), ReplaceValue = Table.ReplaceValue( AddGroupName, " group", "", Replacer.ReplaceText, {"Group Name"} ), FillDown = Table.FillDown(ReplaceValue, {"Group Name"}), RemoveColumns = Table.RemoveColumns(FillDown, {"Is Group"}) in RemoveColumns