Forum Discussion

Mohan128256's avatar
Mohan128256
Helper IV
3 years ago
Solved

Replace Numbers to Text in Power Query

Hi All, I have a sample table data where I am trying to replace 0 with N and 1 with Y using Replacevalue in power query. I cannot add as new custom column because, the same operation i should do on m...
  • BA_Pete's avatar
    3 years ago

    Hi Mohan128256 ,

     

    Try this:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSAeNAIDZQitWJVnICstzdgUQ4EBuChZyBLDc3IOEKF3IBsjw8UDSCjAkJQdHoBBNyhaiKBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", Int64.Type}}),
        Custom1 = Table.ReplaceValue(#"Changed Type", each [Column3], each if ([Column1]="A" or [Column1]="B") and [Column2]="TT" then "change" else [Column3], Replacer.ReplaceValue, {"Column3"}),
    
        Custom2 =
            Table.ReplaceValue(
                Custom1,
                each [Column4],
                each if [Column4] = 0 then "N" else if [Column4] = 1 then "Y" else null,
                Replacer.ReplaceValue,
                {"Column4"}
            )
            
    in
        Custom2

     

    For this output:

     

    Pete