Forum Discussion
Grouping Pivoting and determining current state
I'm a little baffled. I'm ok with basic transformations, but this is a little beyond my experience. Your assistance is greatly appreciated.
I have data that looks like this.
| Client | Component | SubComponent | PercentComplete |
| Client 1 | ItemA | Phase1 | 75 |
| Client 1 | ItemA | Phase2 | 40 |
| Client 1 | ItemA | Phase3 | 0 |
| Client 1 | ItemB | Phase1 | 100 |
| Client 1 | ItemB | Phase2 | 100 |
| Client 1 | ItemB | Phase3 | 100 |
| Client 2 | ItemA | Phase1 | 100 |
| Client 2 | ItemA | Phase2 | 200 |
| Client 2 | ItemA | Phase3 | 10 |
| Client 2 | ItemB | Phase1 | 10 |
| Client 2 | ItemB | Phase2 | 0 |
| Client 2 | ItemB | Phase3 | 0 |
And I need transform it into something that looks like this (where Status is the most advanced phase where Percent > 0 or Status = Complete if all phases are 100 Percent Complete)
| Cient | Component | Status |
| Client1 | ItemA | Phase2 |
| Client1 | ItemB | Complete |
| Client2 | ItemA | Phase3 |
| Client2 | ItemB | Phase1 |
So that I can present the data to my executives in a table/matrix that looks like this
| ItemA | ItemB | |
| Client1 | Phase2 | Complete |
| Client2 | Phase3 | Phase1 |
Thank you.
Hi Steph44 ,
How about the following? 🙂
Before:
After:
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs7JTM0rUTBU0lHyLEnNdQTSARmJxakgAXNTpVgd3EqMgAwTA7xKjIEMrCqckO0xNMCvxogINcaYaoyw+YmQGpCAEQE1ELuwKUHzFl4lRuhhg6ECGnqxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Component = _t, SubComponent = _t, PercentComplete = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client", type text}, {"Component", type text}, {"SubComponent", type text}, {"PercentComplete", Int64.Type}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([PercentComplete] <> 0)), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Client", "Component"}, {{"MaxPhase", each List.Max([#"SubComponent"]), type nullable text}}), #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Client", "Component", "MaxPhase"}, #"Changed Type", {"Client", "Component", "SubComponent"}, "Grouped Rows", JoinKind.LeftOuter), #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"PercentComplete"}, {"PercentComplete"}), #"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "Status", each if [PercentComplete] = 100 then "Complete" else [MaxPhase]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxPhase", "PercentComplete"}) in #"Removed Columns"Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
2 Replies
- tackytechtomMost Valuable Professional
Hi Steph44 ,
How about the following? 🙂
Before:
After:
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs7JTM0rUTBU0lHyLEnNdQTSARmJxakgAXNTpVgd3EqMgAwTA7xKjIEMrCqckO0xNMCvxogINcaYaoyw+YmQGpCAEQE1ELuwKUHzFl4lRuhhg6ECGnqxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Component = _t, SubComponent = _t, PercentComplete = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client", type text}, {"Component", type text}, {"SubComponent", type text}, {"PercentComplete", Int64.Type}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([PercentComplete] <> 0)), #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Client", "Component"}, {{"MaxPhase", each List.Max([#"SubComponent"]), type nullable text}}), #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"Client", "Component", "MaxPhase"}, #"Changed Type", {"Client", "Component", "SubComponent"}, "Grouped Rows", JoinKind.LeftOuter), #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"PercentComplete"}, {"PercentComplete"}), #"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "Status", each if [PercentComplete] = 100 then "Complete" else [MaxPhase]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxPhase", "PercentComplete"}) in #"Removed Columns"Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/- Steph44New Member
Yeah it worked. It was the List.Max feature that did it. I wasn't aware of that feature. Going to need to read more about the functions. Thank you very much