Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to merge rows base on certain value (ID)

Hello All,

 

Hope you are doing well.

Need help on this matter. I have this kind of table with duplication of ID but some of the rows with the same ID completes each other if we can transform them into one column.

IDNameAgeDepartmentJan SalesFeb Sales
1Jose25null2000null
1Jose25nullnull7000
2Imran22null5000null
2Imran22nullnull5000
3Sophea30null20000null
3Sophea30nullnull300

 

I want to transform this table in power query to become this table:

IDNameAgeDepartmentJan SalesFeb Sales
1Jose25null20007000
2Imran22null50005000
3Sophea30null20000300

 

Please help if anyone has any idea how I could achieve this.

Thank you!

  • Anonymous 

    You need two steps to achieve it.

    First, select columns from ID to Department, then Choose unpivot other column,

     

    Then, select the Attribute column, under transform Tab, choose, Pivot Column, Make your selection in the dialog box as follows

     

    Result

     

     

     

     

6 Replies

  • Anonymous 

    You need two steps to achieve it.

    First, select columns from ID to Department, then Choose unpivot other column,

     

    Then, select the Attribute column, under transform Tab, choose, Pivot Column, Make your selection in the dialog box as follows

     

    Result

     

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Fowmy for the solution you sugested. 
      What if I have another column that a bit inconsistance. Observe column 'Supervisor'. Just to mention, the data type of 'Supervisor' column is 'any' or 'text'. Tried your sugesstion but not working for this type table.

       

      IDNameAgeDepartmentSupervisorJan SalesFeb Sales
      1Jose25nullnull2000null
      1Jose25nullnullnull7000
      2Imran22nullNatalie5000null
      2Imran22nullnullnull5000
      3Sophea30nullAlex20000null
      3Sophea30nullnullnull300
      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

        Anonymous 

        Based on your updated data, can you share the expected result ?
        It's not clear how the supervisor field is related to each ID here.



  • add a step between unpivot and pivot and filter without null:

    let
        Quelle = Excel.CurrentWorkbook(){[Name="nasriq_3"]}[Content],
        #"Entpivotierte andere Spalten" = Table.UnpivotOtherColumns(Quelle, {"ID", "Name", "Age", "Department"}, "Attribute", "Value"),
    
        #"Gefilterte Zeilen" = Table.SelectRows(#"Entpivotierte andere Spalten", each ([Value] <> "null")),
    
        #"Pivotierte Spalte" = Table.Pivot(#"Gefilterte Zeilen", List.Distinct(#"Gefilterte Zeilen"[Attribute]), "Attribute", "Value")
    in
        #"Pivotierte Spalte"