Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AlexisKMX
Frequent Visitor

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 column has a 1 then there should be placed the value of the column [Value].

 

For example, the first row, "OK" should be placed in the column [Status] because there is a 1 there.

 

The other thing after achieve that is to merge the duplicates values in the column [QuestionNo] in just one row, basically put it together in one row, and that the values ​​of the columns on the right are also put together in the same row. For example in the Q4, there are four Q4 since it has values in [Rank], [Finding] and [Responsible], but i want those values to be in just one single row to have only one Q4. 

 

InkedPowerBI Query Req.jpg

 

Please let me know if my explanation wasn't clear at all and i will really appreciate all your advices.

 

 

Thanks people!

1 ACCEPTED SOLUTION

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.

vkalyjmsft_0-1663149936217.png

 

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.

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @AlexisKMX ,

According to your description, I create a sample.

vkalyjmsft_0-1662713230162.png

Here's my solution:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjRU0lHy9wYSIAYIxeoARY1gojAJsKgxkihYAixqAmQ6oxtggtUAkKifO7IBsQA=", 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]),
    #"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"}, {{"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"}, {{"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"

Get the result:

vkalyjmsft_1-1662713305648.png

I attach my sample below for your reference.

 

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.

My problem is that I have a column named Input ID, from 1 to 56, each Input ID has its own 23 Questions from Q1 to Q23. How can i group first the Input ID and then group the QuestionNo to then fill up the rows?

 

AhoraSi.png

 

Here is a picture of reference.

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.

vkalyjmsft_0-1663149936217.png

 

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.

Thanks for the support! Exactly what i need. 

Thanks a lot for the answer Kalyj

 

I'm just struggling with the fact that i have other columns in my main table, and when i declared the variable cols, it takes all columns but i want to take only the ones that i want to group. Is it possible to grab only specific columns in my table? and then properly declare cols with specific columns of my table?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.