Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Moving Rows into columns with Unique ID

Hello, I have a much larger set of data similar to below. I want to get it so Unique ID is in the row, and the Course Title is in the column. 

 

So from this:

TitleLearner IDLearner NameStatusDivision
Course 1ID1BobCompletedPayroll
Course 1ID2SarahCompletedHR
Course 1ID3AliceCompletedSales
Course 1ID4MarkIncompleteMarketing
Course 2ID1BobIncompletePayroll
Course 2ID2SarahIncompleteHR
Course 2ID3AliceIncompleteSales
Course 2ID4MarkCompletedMarketing
Course 3ID1BobCompletedPayroll
Course 3ID2SarahCompletedHR
Course 3ID3AliceIncompleteSales
Course 3ID4MarkCompletedMarketing

 

To this:

Learner IDLearner NameCourse 1Course 2Course 3Division
ID1BobCompletedIncompleteCompletedPayroll
ID2SarahCompletedIncompleteCompletedHR
ID3AliceCompletedIncompleteIncompleteSales
ID4MarkIncompleteCompletedCompletedMarketing

 

I've tried Pivot Columns but it doesnt merge the ID. 

 

Thanks in advance.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,
    Thanks for amitchandak  reply.
    Here some steps that I want to share, you can check them if they suitable for your requirement.
    Here is my test data:

    Click "Transform data" and open power query
    Select the Title column and select the pivot column in the Transform toolbar, then in the screen that opens select Status in the value column and select the Don't Aggregate option in the Aggregate Value function.Select the Title column and select the pivot column in the Transform toolbar, then in the screen that opens select Status in the value column and select the Don't Aggregate option in the Aggregate Value function.

    Final output

    You can also use this m code in advanced editor

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZCxDsIgEIZfpWHuIvgC2g420cZYt6bDWS9KpGCAmvj2QtKhQAe7/Lk7/v/ycW1LrtwKJDk5ImiJOqvKWVPD4N8aC3Y0rij5hxuuJOnylhRq1AazjZtXpde9ujkt1PAWaPHu6jN8tRIitVO/FTQ8o8DhknqZ053gPUbeBgSa1L51egL98o3sJ/80Q8vlYx6hEXyQWKCnCX2QCPFpgh+YE34a889/u4jP1t2erbg9WwnP/oTvfg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Title", type text}, {"Learner ID", type text}, {"Learner Name", type text}, {"Status", type text}, {"Division", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Title]), "Title", "Status")
    in
        #"Pivoted Column"

     

    Best regards,

    Albert He

     

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

     

     

     

4 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Unpivot seems to be putting data in rows rather than columns.

       

      I want the row to group all courses in columns with the one unique ID.

       

      To this:

      Learner IDLearner NameCourse 1Course 2Course 3Division
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,
    Thanks for amitchandak  reply.
    Here some steps that I want to share, you can check them if they suitable for your requirement.
    Here is my test data:

    Click "Transform data" and open power query
    Select the Title column and select the pivot column in the Transform toolbar, then in the screen that opens select Status in the value column and select the Don't Aggregate option in the Aggregate Value function.Select the Title column and select the pivot column in the Transform toolbar, then in the screen that opens select Status in the value column and select the Don't Aggregate option in the Aggregate Value function.

    Final output

    You can also use this m code in advanced editor

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZCxDsIgEIZfpWHuIvgC2g420cZYt6bDWS9KpGCAmvj2QtKhQAe7/Lk7/v/ycW1LrtwKJDk5ImiJOqvKWVPD4N8aC3Y0rij5hxuuJOnylhRq1AazjZtXpde9ujkt1PAWaPHu6jN8tRIitVO/FTQ8o8DhknqZ053gPUbeBgSa1L51egL98o3sJ/80Q8vlYx6hEXyQWKCnCX2QCPFpgh+YE34a889/u4jP1t2erbg9WwnP/oTvfg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Title", type text}, {"Learner ID", type text}, {"Learner Name", type text}, {"Status", type text}, {"Division", type text}}),
        #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Title]), "Title", "Status")
    in
        #"Pivoted Column"

     

    Best regards,

    Albert He

     

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

     

     

     

    • Whibley92's avatar
      Whibley92
      Helper II

      Anonymous thanks, it doesnt work with "Status" as the completion dates are different so doesn't merge the IDs into one row. I had to add a custom column with the completion date which doesnt look as good. 

       

      Is there a way round this? I would like to keep the completion dates as they are useful later on for analysis, but in this instance I would rather it just said complete.