Forum Discussion

AlexisKMX's avatar
AlexisKMX
Frequent Visitor
3 years ago
Solved

Power Query Merge Rows

Hi friends!   I was modifying this table in Power Query but i got stuck in this step. Basically what i want to do is to distribute the column [Value] in all the other columns to its right. If the c...
  • v-yanjiang-msft's avatar
    v-yanjiang-msft
    3 years ago

    Hi AlexisKMX ,

    Sorry for late back. Based my understanding, I modify the sample and the code, please refer to it:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjRU0lHy9wYSIAYEGSrF6gBljGAyCEmojDGSDFQSKmMCZDpjM8wEp2EgGT93bIZhcZoRmgxCEosMVNII4R1nbIYZ4zQMi9OAMrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [QuestionNo = _t, Value = _t, Status = _t, Rank = _t, Finding = _t, #"Input ID" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"QuestionNo", type text}, {"Value", type text}, {"Status", Int64.Type}, {"Rank", Int64.Type}, {"Finding", Int64.Type}}),
        cols=Table.ColumnNames(Source),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type",1,each [Value], Replacer.ReplaceValue,cols),
        #"Grouped Rows" = Table.Group(#"Replaced Value", {"QuestionNo","Input ID"}, {{"Group", each Table.FillUp(_,cols)}}),
        #"Expanded Group" = Table.ExpandTableColumn(#"Grouped Rows", "Group", {"Value", "Status", "Rank", "Finding"}, {"Group.Value", "Group.Status", "Group.Rank", "Group.Finding"}),
        #"Group Rows2" = Table.Group(#"Expanded Group", {"QuestionNo","Input ID"}, {{"Group", each Table.FirstN(_,1)}}),
        #"Expanded Group1" = Table.ExpandTableColumn(#"Group Rows2", "Group", {"Group.Value", "Group.Status", "Group.Rank", "Group.Finding"}, {"Group.Group.Value", "Group.Group.Status", "Group.Group.Rank", "Group.Group.Finding"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded Group1",{"Group.Group.Value"})
    in
        #"Removed Columns"

    I only modify the group step, add the Input ID column in the Table.Group function.

     

    Best Regards,
    Community Support Team _ kalyj

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