Forum Discussion

VinayakDeb's avatar
VinayakDeb
New Member
3 years ago

Replace value in one cell based on condition on another

Hi,

I'm very new to PowerBI and I need your help. I tried various options including conditional columns, but it doesn't seem to work. They all add extra columns, that I would like to avoid.  

I'm recovering an excel file with two columns "Groupe Description" & "Categorie".

For Groupe Description value "BMW Finance NV" I want to force the category "INSTIT" instead of  default "CORPOR"

All other rows remain untouched. 

 

I tried the code below that I found on this website elsewhere, but it doesn't help.

 

#"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [Categorie],each if [Groupe Description]= "BMW FINANCE NV" and [Categorie]="CORPOR" then "INSTIT" else [Categorie],Replacer.ReplaceText,{"Categorie"})

 

Please see the below image. 

 

 

Thanks in advance for any help you can provide. 

Regards,

Vinayak

 

1 Reply

  • There are several things that you can try.

    1. Click over 'CORPOR' AND 'BMW FINANCE NV' and select the text in order to check that you don't have spaces at the end of your text. (if you have spaces remember that you can trim the columns)

    2. You could try to use Replacer.ReplaceValue instead of Replacer.ReplaceText.

    3. If it doesn't work, you could try to change types and use both replaces again.

    4. If nothing works, you could try to use Text.Contains([Categorie], "CORPOR").

     

    I've noticed that the name of the column is in capital letters but it's not in the formula. I supose because it's an example.