Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to replace a value in a column with the column name

Hi there,

 

Could someone please tell me how I can replace values in a column with the column name.

 

As a simple example, I want PQ to replace every 'Nein' with the column name:

 

 

Is this doable?

 

Thanks.

  • NewStep= Table.ReplaceErrorValues(PreviousStepName,List.Transform(Table.ColumnNames(PreviousStepName),(x)=>{x,x}))

4 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    NewStep=Table.TransformColumns(PreviousStepName,List.Transform(Table.ColumnNames(PreviousStepName),each {_,(x)=>if x="Nein" then _ else x}))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Daniel,

       

      It works perfectly! Thank you!

       

      How can I please apply your solution when I want to replace errors, instead of a specific value, with the column name?:

       

       

      Looking forward to hearing back from you.

       

      • wdx223_Daniel's avatar
        wdx223_Daniel
        Icon for Community Champion rankCommunity Champion

        NewStep= Table.ReplaceErrorValues(PreviousStepName,List.Transform(Table.ColumnNames(PreviousStepName),(x)=>{x,x}))