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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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