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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Simonne
New Member

Direct Query- Replace a piece of string if certain conditions met from another column

Hi Power BI community! Newby here, and I need help! 
I've got a direct query project started and I need to replace a component of text in one column if conditions are met from another column.

Example. If column1 is Alberta OR British Columbia, a portion of Column 2 string needs to change: from C1 to C2. I need the rest of string to stay the same.

Before:                

Column 1Column 2
AlbertaC1Triangle
AlbertaC1Circle
QuebecC1Circle
British ColumbiaC1Square
NewfoundlandC2Circle

 

After:                

Column 1Column 2
AlbertaC2Triangle
AlbertaC2Circle
QuebecC1Circle
British ColumbiaC2Square
NewfoundlandC2Circle


Thank you!!!

1 ACCEPTED SOLUTION
uzuntasgokberk
Super User
Super User

Hello @Simonne ,

I prefer to choose Power Query transformations for best practice. So transform data(power query) --> Add column --> Custom Column:
if [Column]="Alberta" or [Column]="Columbia" then Text.Replace([Column],"C1","C2") else [Column]

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

View solution in original post

6 REPLIES 6
Simonne
New Member

Ok I got it! Thank you both!!! 

uzuntasgokberk
Super User
Super User

Hello @Simonne ,

I prefer to choose Power Query transformations for best practice. So transform data(power query) --> Add column --> Custom Column:
if [Column]="Alberta" or [Column]="Columbia" then Text.Replace([Column],"C1","C2") else [Column]

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

Perfect, it worked thank you!!

muhammad_786_1
Super User
Super User

Hi @Simonne 

You can create a new column by using this DAX:

 

Upd_Column2 = 
IF(
    'Table'[Column1] = "Alberta" || 'Table'[Column1] = "British Columbia",
    SUBSTITUTE('Table'[Column2], "C1", "C2"),
    'Table'[Column2]
)

 

muhammad_786_1_0-1731675399701.png

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

Thanks @muhammad_786_1 !

I tried using add custom column in queries.. is that wrong?
Here's what I see:

Simonne_1-1731676664082.png

 

 




Hi @Simonne 

 

You just need to select Table View, then select New Column, and paste the DAX formula there. This will create a new calculated column.

 

muhammad_786_1_0-1731677182638.png

 

However, if you prefer using Power Query, you can achieve the same result by adding a Custom Column directly in the Power Query Editor.

 

muhammad_786_1_1-1731677699508.png

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.