Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hello,
Is there any way to replace the value of a cell with the Header Name for different columns at the same time?
I have multiple columns when the value is Yes, and I need to change this Yes with the name of column. I know how to do it one by one, and copying and pasting the header name, but not for all at the same time and naming with code the header name directly in M Query.
= Table.ReplaceValue(#"Replaced Value1","Yes","Header Name 1",Replacer.ReplaceText,{"Header Name 1"})
Thanks
Solved! Go to Solution.
how about this solution?
let
Quelle = Excel.CurrentWorkbook(){[Name="PFC"]}[Content],
#"Tiefer gestufte Header" = Table.DemoteHeaders(Quelle),
#"Transponierte Tabelle" = Table.Transpose(#"Tiefer gestufte Header"),
ListHeader = List.RemoveFirstN(Table.ColumnNames(#"Transponierte Tabelle"),1),
ErsetzterWert = Table.ReplaceValue(#"Transponierte Tabelle","Yes", each _[Column1],Replacer.ReplaceText,ListHeader),
#"Transponierte Tabelle1" = Table.Transpose(ErsetzterWert),
#"Höher gestufte Header" = Table.PromoteHeaders(#"Transponierte Tabelle1", [PromoteAllScalars=true])
in
#"Höher gestufte Header"Melanie
OK. Then instead of
(col) => {col, each _ & " " & col, type text}
use
(col) => {col, each if _ = "Yes" then col else _, type text}
how about this solution?
let
Quelle = Excel.CurrentWorkbook(){[Name="PFC"]}[Content],
#"Tiefer gestufte Header" = Table.DemoteHeaders(Quelle),
#"Transponierte Tabelle" = Table.Transpose(#"Tiefer gestufte Header"),
ListHeader = List.RemoveFirstN(Table.ColumnNames(#"Transponierte Tabelle"),1),
ErsetzterWert = Table.ReplaceValue(#"Transponierte Tabelle","Yes", each _[Column1],Replacer.ReplaceText,ListHeader),
#"Transponierte Tabelle1" = Table.Transpose(ErsetzterWert),
#"Höher gestufte Header" = Table.PromoteHeaders(#"Transponierte Tabelle1", [PromoteAllScalars=true])
in
#"Höher gestufte Header"Melanie
This is also working, but I have taken the solution from Alexis cause the necessary steps are less.
Thanks for your reply in any case
You can transform multiple columns by using List.Transform to build a list of column transformations like this:
= Table.TransformColumns(
#"Changed Type",
List.Transform(
{"Boolean", "Letter"},
(col) => {col, each _ & " " & col, type text}
)
)
Starting table:
Transformed table:
Full sample query you can paste into the Advanced Editor of a new blank query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WikwtVtJRcgRiQ6VYHRjfCYiNwHy/fCDTGYiNlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Boolean = _t, Letter = _t, Number = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Boolean", type text}, {"Letter", type text}, {"Number", Int64.Type}}),
#"Embedded Headers" = Table.TransformColumns(#"Changed Type", List.Transform({"Boolean", "Letter"}, (col) => {col, each _ & " " & col, type text}))
in
#"Embedded Headers"
Thanks for your answer. My idea was changing the Yes by the Header Name, not include in all the columns the header name. Is it a way to perform this?
Can you give a simple example demonstrating what you mean?
Yes sure:
Initial data
| Title | Name 1 | Name 2 | Name 3 | Name 4 |
| A | Yes | No | No | Yes |
| B | No | Yes | No | Yes |
Expected outcome
| Title | Name 1 | Name 2 | Name 3 | Name 4 |
| A | Name 1 | No | No | Name 4 |
| B | No | Name 2 | No | Name 4 |
OK. Then instead of
(col) => {col, each _ & " " & col, type text}
use
(col) => {col, each if _ = "Yes" then col else _, type text}
Thanks, this is correctly working
Hello - you can unpivot the columns in which the values needing to be replaced, which will give you one column for all of the column names and one column for all of their corresponding values. Then apply the replacements function to the values column and pivot back.
Thanks for your answer. I was searching something to be done without pivot and unpivot in order to do it with the replace function, although this is also having the same result. I will leave the issue open in case someone knows how to do it and if not I will accept this solution.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |