Forum Discussion

JS's avatar
JS
Helper II
8 years ago
Solved

Help in Data modelling

Hello. 

 

I need some help with data modelling here! I have the table below - 

 

BuyerGreen AppleRed AppleOrangePineappleKiwiStrawberry
James100000
James000010
Mary010000
Mary000001
Mary100000
John010000
John001000
John000010

 

I would like to convert the table to what is shown below - 

 

BuyerGreen AppleRed AppleOrangePineappleKiwiStrawberry
James100010
Mary110001
John011010

 

 

Is there any quick way to get this done. Any help or advise would be grateful! 

 

Thanks

JS

  • Yes, it can be done easily in Power Query:

     

    (1) unpivot all the non-Buyer columns, so that you get a table with 3 columns: Buyer, Fruit, Qty

    (2) group by both Buyer and Fruit columns, summing over Qty

    (3) finally, pivot the Fruit and Qty columns

     

     

2 Replies

  • Yes, it can be done easily in Power Query:

     

    (1) unpivot all the non-Buyer columns, so that you get a table with 3 columns: Buyer, Fruit, Qty

    (2) group by both Buyer and Fruit columns, summing over Qty

    (3) finally, pivot the Fruit and Qty columns

     

     

    • JS's avatar
      JS
      Helper II

      Thank you!!!! Worked perfectly!!!!