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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jerryr125
Helper III
Helper III

populate a row with the name of a field

Hi - I have the following data and I would like to populate any non-null values with the field name concatenated before the value.

 

Example

Starting Data

 

IDName1Name2Name3
1RequiredApprovednull
2ExpiredRequiredOverdue
3nullRequirednull

 

Final Table - What I am looking to do :

 

IDName1Name2Name3
1Name1-RequiredName2-Approvednull
2Name1-ExpiredName2-RequiredName3-Overdue
3nullName2-Requirednull

 

Any thoughts  ? Jerry

 

3 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKLSzNLEpNATIdCwqK8svAzLzSnBylWJ1oJSMgx7WiAKoCSbF/WWpRSmkqWJExTAeKCogZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name1 = _t, Name2 = _t, Name3 = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns",each [Value],each if [Value]="null" then null else [Attribute] & "-" & [Value],Replacer.ReplaceValue,{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

c

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

View solution in original post

dufoq3
Super User
Super User

Hi @jerryr125, different approach with List.Accumulate:

 

Output

dufoq3_0-1726508455748.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKLSzNLEpNATIdCwqK8svAzLzSnBylWJ1oJSMgx7WiAKoCSbF/WWpRSmkqWJExTAeKCogZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name1 = _t, Name2 = _t, Name3 = _t]),
    Transformed = List.Accumulate(
        List.Skip(Table.ColumnNames(Source)),
        Source,
        (s,c)=> Table.TransformColumns(s, {{c, each if List.Contains({null, "null"}, _) then null else c & "-" & _, type text}}) )
in
    Transformed

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

Omid_Motamedise
Super User
Super User

RIGHT CLICK ON ID COLUMN AND PICK UNPIVOT OTHER COLUMN TO REACH THE NEXT TABLE

 

Omid_Motamedise_4-1726536507282.png

 

Add a new custom column by the next formula

[Attribute]&"-"&[Value]

 

to reach the next result

 

Omid_Motamedise_5-1726536517208.png

 

 

 

remove column valu and then select attribute column and from transform tab pick pivot and then pick custom column and like the next image from advance setting pick do not aggregate

 

Omid_Motamedise_2-1726536391405.png

 

 

pres ok to result in 

 

Omid_Motamedise_6-1726536528716.png

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

3 REPLIES 3
Omid_Motamedise
Super User
Super User

RIGHT CLICK ON ID COLUMN AND PICK UNPIVOT OTHER COLUMN TO REACH THE NEXT TABLE

 

Omid_Motamedise_4-1726536507282.png

 

Add a new custom column by the next formula

[Attribute]&"-"&[Value]

 

to reach the next result

 

Omid_Motamedise_5-1726536517208.png

 

 

 

remove column valu and then select attribute column and from transform tab pick pivot and then pick custom column and like the next image from advance setting pick do not aggregate

 

Omid_Motamedise_2-1726536391405.png

 

 

pres ok to result in 

 

Omid_Motamedise_6-1726536528716.png

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
dufoq3
Super User
Super User

Hi @jerryr125, different approach with List.Accumulate:

 

Output

dufoq3_0-1726508455748.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKLSzNLEpNATIdCwqK8svAzLzSnBylWJ1oJSMgx7WiAKoCSbF/WWpRSmkqWJExTAeKCogZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name1 = _t, Name2 = _t, Name3 = _t]),
    Transformed = List.Accumulate(
        List.Skip(Table.ColumnNames(Source)),
        Source,
        (s,c)=> Table.TransformColumns(s, {{c, each if List.Contains({null, "null"}, _) then null else c & "-" & _, type text}}) )
in
    Transformed

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpKLSzNLEpNATIdCwqK8svAzLzSnBylWJ1oJSMgx7WiAKoCSbF/WWpRSmkqWJExTAeKCogZsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name1 = _t, Name2 = _t, Name3 = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns",each [Value],each if [Value]="null" then null else [Attribute] & "-" & [Value],Replacer.ReplaceValue,{"Value"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

c

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.

Top Solution Authors