Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Place rows in column based on duplicate value

Good day all, 

 

It would help me out big time if someone could help me with the follwing: 

 

Currently my data is stored this way:

JobStepPU AtDO At
11ab
12bc
13cd
21ef
31gh
32hi

 

However, I need it the following way:

JobStep 1PU At 1DO At 1Step 2PU At 2DO At 2Step 3PU At 3DO At 3
11ab2bc3cd
21efnullnullnullnullnullnull
31gh2ghnullnullnull

 

The steps can go up to 10, so that needs to be the maximum amount. Is this possible and if so how can I arrange this. If you need more info please ask.

 

Thank you in advance!

  • Anonymous , Paste this code into a blank query in power query and check out the tranformations

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeNEIE5SitWBiBiBeTpKyXARYzBPRykFLGIE1ZUKxGlgEWOoSDoQZ8BFjMA8HaVMpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Job = _t, Step = _t, #"PU At" = _t, #"DO At" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Job", Int64.Type}, {"Step", Int64.Type}, {"PU At", type text}, {"DO At", type text}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Step", "Step - Copy"),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Duplicated Column", {"Job", "Step - Copy"}, "Attribute", "Value"),
        #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Step - Copy", type text}}, "en-US"),{"Attribute", "Step - Copy"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
        #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value", List.Max)
    in
        #"Pivoted Column"

2 Replies

  • Anonymous , Paste this code into a blank query in power query and check out the tranformations

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAeNEIE5SitWBiBiBeTpKyXARYzBPRykFLGIE1ZUKxGlgEWOoSDoQZ8BFjMA8HaVMpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Job = _t, Step = _t, #"PU At" = _t, #"DO At" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Job", Int64.Type}, {"Step", Int64.Type}, {"PU At", type text}, {"DO At", type text}}),
        #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Step", "Step - Copy"),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Duplicated Column", {"Job", "Step - Copy"}, "Attribute", "Value"),
        #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Columns", {{"Step - Copy", type text}}, "en-US"),{"Attribute", "Step - Copy"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
        #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value", List.Max)
    in
        #"Pivoted Column"
    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes, this shows the table I put in the orginal question thanks! But how do I arrange to have it use the data I need to use?