Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
pjpkumar26
New Member

Power Bi Query

Hi Team,

How to create a condition on text field 

I got a field "Harm" and the values are :

Harm

A

B

C

D

 

i am trying to create a condition like 

if (Harm =A then "nom",Harm =B,"pol" else Harm)

 

what is the best way to do this in Power query please?

Thanks,

Kumar

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

If you are trying to replace the values in the original column you can add the following code to your query...

Table.ReplaceValue(previousTableStep,each [Harm],each if [Harm] = "A" then "nom" else if [Harm] = "B" then "pol" else [Harm],Replacer.ReplaceText,{"Harm"})

jgeddes_0-1727182379394.png

If you want a new column then use the 'Conditional Column' button on the 'Add Column' ribbon.

jgeddes_1-1727182483207.pngjgeddes_2-1727182500282.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
Omid_Motamedise
Super User
Super User

It is true, just put the column name inside [] like

 

if [Harm]="" ,,,,,,,,

 

so go to the transform tab and pick add new column and start to write your formula in the bellow syntax

 

 

if ......... then ................ else ........................


If my answer helped solve your issue, please consider marking it as the accepted solution.
jgeddes
Super User
Super User

If you are trying to replace the values in the original column you can add the following code to your query...

Table.ReplaceValue(previousTableStep,each [Harm],each if [Harm] = "A" then "nom" else if [Harm] = "B" then "pol" else [Harm],Replacer.ReplaceText,{"Harm"})

jgeddes_0-1727182379394.png

If you want a new column then use the 'Conditional Column' button on the 'Add Column' ribbon.

jgeddes_1-1727182483207.pngjgeddes_2-1727182500282.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors