Forum Discussion

PowerAppsUser's avatar
PowerAppsUser
Frequent Visitor
4 years ago
Solved

Replace Values not working

Hi,

I am trying to replace the value of a cell with another value in Power Query by right clicking that cell and using 'Replace Value', but it doesnt seem to work. I want to change "null" to "Electricity". The function bar is showing the following function :

= Table.ReplaceValue(#"Trimmed Text",null,"Electricity",Replacer.ReplaceValue,{"Sector"})

But the cell value is not changing. Please let me know if anyone knows how to fix it.

Thanks!

  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    Ah, it sounds like you had the text "null" rather than actual nulls. I didn't pick that up upon the first read.

     

    In that case, you can skip the uppercase transformation and just use "null" instead of null in your original M code (insert the quotes into the formula):

    = Table.ReplaceValue(#"Trimmed Text","null","Electricity",Replacer.ReplaceValue,{"Sector"})

     

6 Replies

  • It might be an empty string "" instead of a null. See if this works:

     

    = Table.ReplaceValue(#"Trimmed Text","","Electricity",Replacer.ReplaceValue,{"Sector"})

    Or as Samarth_18 suggests, it might be a space or some other type of whitespace.

     

  • PowerAppsUser's avatar
    PowerAppsUser
    Frequent Visitor

    Thank you Samarth and Alexis for your help, I tried out both of your suggesions but somehow they dint work. So I tried another work around that finally worked - I changed the case of the column to UPPERCASE and made null as NULL, and then when I tried to change it with 'Replace Value', I was able to change it to Electricity. Then I went back and removed the UPPERCASE.

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      Ah, it sounds like you had the text "null" rather than actual nulls. I didn't pick that up upon the first read.

       

      In that case, you can skip the uppercase transformation and just use "null" instead of null in your original M code (insert the quotes into the formula):

      = Table.ReplaceValue(#"Trimmed Text","null","Electricity",Replacer.ReplaceValue,{"Sector"})

       

      • PowerAppsUser's avatar
        PowerAppsUser
        Frequent Visitor

        Your right! I tried your code with "null" and it worked! But I still wonder why the 'Replace Values' dint work.

         

        Thank you, Alexis!