Forum Discussion

MSuser5's avatar
MSuser5
Helper III
3 years ago
Solved

converting rows into column in powerquery

Hi All,

I have source data which is contain row level process step and i need to split into column level data in edit query transformation level.

ex: source file

 

 

Expected result using edit query: (Process row steps (input,reject,input2,review,review2,print)  need to convert into column level with IN and OUT time)

result:

thanks,

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  MSuser5 ,

     

    Here are the steps you can follow:

    1. Go to Power Query check [IN], [Out] Unpivot Columns.

    Result:

    2. Transform – Group  -- [ID] – Operation:All Rows.

    3. Add Column – Custom Column – Enter the following code.

    Table.AddIndexColumn([Count],"Rank",1,1)

    4. Selected [Count] – Remove.

    5. Expand [Custom] - Do not select column [ID] - OK.

    6. Select the three columns [Custom.Process], [Custom.Attribute], [Custom.Rank] -- right mouse button in the Merge Column interface to set the information at the yellow label.

    7. Select [Merged] -- Transform Pivot Column.

    Value Column  --  [Custom.Value].

    Advanced options Dont Aggregate.

    8. Result:

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  MSuser5 ,

     

    Here are the steps you can follow:

    1. Go to Power Query check [IN], [Out] Unpivot Columns.

    Result:

    2. Transform – Group  -- [ID] – Operation:All Rows.

    3. Add Column – Custom Column – Enter the following code.

    Table.AddIndexColumn([Count],"Rank",1,1)

    4. Selected [Count] – Remove.

    5. Expand [Custom] - Do not select column [ID] - OK.

    6. Select the three columns [Custom.Process], [Custom.Attribute], [Custom.Rank] -- right mouse button in the Merge Column interface to set the information at the yellow label.

    7. Select [Merged] -- Transform Pivot Column.

    Value Column  --  [Custom.Value].

    Advanced options Dont Aggregate.

    8. Result:

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • MSuser5's avatar
      MSuser5
      Helper III

      Hi Anonymous,

       

      Great it's working now as expected ..

      Thanks,

      MS

       

    • user131313's avatar
      user131313
      Frequent Visitor

      Hi,

       

      This is really helpful - I have a follow up requirement though and wanted to ask thoughts on this! If you wanted the number appended on to the new columns to be more consistent (i.e. IN 1, OUT 1, IN 2, OUT 2) how would you do this without going through and manually renaming columns (as your number of columns is dynamic)?

       

      Many thanks! 😊

  • Please do not do that. It is the opposite of what Power BI is about.  You can easily show the data in a matrix visual like that (although I would also recommend you reconsider) but please don't do that.  Quite the opposite, you should unpivot your data even more 

     

    ID |  Process |  Type |  Date

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MSuser5 ,

     

    Here are the steps you can follow:

    1. Go to Power Query – check [IN], [Out] – Unpivot Columns.

    Result:

    2. Add Column – Index Column – From 1.

    3. Select the three columns [Process], [Attribute], [Index] -- right mouse button – in the Merge Column interface – to set the information at the yellow label.

    4. Select [Merged] -- Transform – Pivot Column.

    Value Column  --  [Value].

    Advanced options – Don’t Aggregate.

    5. Result:

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

      • lbendlin's avatar
        lbendlin
        Super User

        Based on your sample data, which six columns would you expect to see?