cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Atleti
Frequent Visitor

Custom columns that return values with same ID

Hey all,

 

I'm dealing with some survey data and hoping I could get some help here. 

I would like to be able to split out any given response value into a column, and then apply it to each row with the same ID. So make something like:

 

IDSurvey TitleResponse Value
1

What color?

blue
1

What number?

2
1

Supplier name?

Durant's
1What location?patio
2What number?2
2Supplier Name?FurnCo
2What color?red
2What location?basement

 

Looks something like:

 

IDSurvey TitleResponse ValueColorSupplier
1

What color?

blueblueDurant's
1

What number?

2blueDurant's
1

Supplier name?

Durant'sblueDurant's
1What location?patioblueDurant's
2What number?2redFurnCo
2Supplier Name?FurnCoredFurnCo
2What color?redredFurnCo
2What location?basementredFurnCo

 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Atleti 

You can refer to the following example.

Create two "Blank Query" in power query

vxinruzhumsft_0-1675733996611.png

 

Then put the following code to Advanced Editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrPSCxRSM7PyS+yB/KSckpTlWJ1kKTySnOTUsFyRnCJ4NKCgpzM1CKFvMTcVJCUS2lRYl5JTKmBgZF5Mar+nPzkxJLM/DyQsgIQCyxthMt4I2Tj/aDGu5UW5TmjaYQ7uSg1BVUG2cakxOLU3NS8EqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Survey Title" = _t, #"Response Value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Survey Title", type text}, {"Response Value", type text}})
in
    #"Changed Type"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrPSCxRSM7PyS+yB/KSckpTlWJ1kKTySnOTUsFyRnCJ4NKCgpzM1CKFvMTcVJCUS2lRYl5JTKmBgZF5Mar+nPzkxJLM/DyQsgIQCyxthMt4I2Tj/aDGu5UW5TmjaYQ7uSg1BVUG2cakxOLU3NS8EqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Survey Title" = _t, #"Response Value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Survey Title", type text}, {"Response Value", type text}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Changed Type",{{"Survey Title", Text.Proper, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Capitalized Each Word", List.Distinct(#"Capitalized Each Word"[#"Survey Title"]), "Survey Title", "Response Value"),
    #"Merged Queries" = Table.NestedJoin(#"Pivoted Column", {"ID"}, #"Query1", {"ID"}, "Query1", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Survey Title", "Response Value"}, {"Survey Title", "Response Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Table (2)",{"ID", "Survey Title", "Response Value", "What Color?", "What Number?", "Supplier Name?", "What Location?"})
in
    #"Reordered Columns"

Output

vxinruzhumsft_1-1675734100166.png

 

Best Regards!

Yolo Zhu

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

1 REPLY 1
v-xinruzhu-msft
Community Support
Community Support

Hi @Atleti 

You can refer to the following example.

Create two "Blank Query" in power query

vxinruzhumsft_0-1675733996611.png

 

Then put the following code to Advanced Editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrPSCxRSM7PyS+yB/KSckpTlWJ1kKTySnOTUsFyRnCJ4NKCgpzM1CKFvMTcVJCUS2lRYl5JTKmBgZF5Mar+nPzkxJLM/DyQsgIQCyxthMt4I2Tj/aDGu5UW5TmjaYQ7uSg1BVUG2cakxOLU3NS8EqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Survey Title" = _t, #"Response Value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Survey Title", type text}, {"Response Value", type text}})
in
    #"Changed Type"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQrPSCxRSM7PyS+yB/KSckpTlWJ1kKTySnOTUsFyRnCJ4NKCgpzM1CKFvMTcVJCUS2lRYl5JTKmBgZF5Mar+nPzkxJLM/DyQsgIQCyxthMt4I2Tj/aDGu5UW5TmjaYQ7uSg1BVUG2cakxOLU3NS8EqXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Survey Title" = _t, #"Response Value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Survey Title", type text}, {"Response Value", type text}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Changed Type",{{"Survey Title", Text.Proper, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Capitalized Each Word", List.Distinct(#"Capitalized Each Word"[#"Survey Title"]), "Survey Title", "Response Value"),
    #"Merged Queries" = Table.NestedJoin(#"Pivoted Column", {"ID"}, #"Query1", {"ID"}, "Query1", JoinKind.LeftOuter),
    #"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Survey Title", "Response Value"}, {"Survey Title", "Response Value"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Table (2)",{"ID", "Survey Title", "Response Value", "What Color?", "What Number?", "Supplier Name?", "What Location?"})
in
    #"Reordered Columns"

Output

vxinruzhumsft_1-1675734100166.png

 

Best Regards!

Yolo Zhu

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

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors