Forum Discussion

Steph44's avatar
Steph44
New Member
2 years ago
Solved

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. 

 

ClientComponentSubComponent PercentComplete
Client 1ItemAPhase175
Client 1ItemAPhase240
Client 1ItemAPhase30
Client 1ItemBPhase1100
Client 1ItemBPhase2100
Client 1ItemBPhase3100
Client 2ItemAPhase1100
Client 2ItemAPhase2200
Client 2ItemAPhase310
Client 2ItemBPhase110
Client 2ItemBPhase20
Client 2ItemBPhase30

 

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)

 

CientComponentStatus
Client1ItemAPhase2
Client1ItemBComplete
Client2ItemAPhase3
Client2ItemBPhase1

 

So that I can present the data to my executives in a table/matrix that  looks like this

 

 ItemAItemB
Client1Phase2Complete
Client2Phase3Phase1

 

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

  • tackytechtom's avatar
    tackytechtom
    Most 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/

    • Steph44's avatar
      Steph44
      New 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