Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
ID | Name1 | Name2 | Name3 |
1 | Required | Approved | null |
2 | Expired | Required | Overdue |
3 | null | Required | null |
Final Table - What I am looking to do :
ID | Name1 | Name2 | Name3 |
1 | Name1-Required | Name2-Approved | null |
2 | Name1-Expired | Name2-Required | Name3-Overdue |
3 | null | Name2-Required | null |
Any thoughts ? Jerry
Solved! Go to Solution.
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.
Hi @jerryr125, different approach with List.Accumulate:
Output
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
RIGHT CLICK ON ID COLUMN AND PICK UNPIVOT OTHER COLUMN TO REACH THE NEXT TABLE
Add a new custom column by the next formula
[Attribute]&"-"&[Value]
to reach the next result
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
pres ok to result in
RIGHT CLICK ON ID COLUMN AND PICK UNPIVOT OTHER COLUMN TO REACH THE NEXT TABLE
Add a new custom column by the next formula
[Attribute]&"-"&[Value]
to reach the next result
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
pres ok to result in
Hi @jerryr125, different approach with List.Accumulate:
Output
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
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.
Check out the July 2025 Power BI update to learn about new features.