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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
dats
Resolver I
Resolver I

conditionally replacing values

Hi

 

I read in a blog that you can conditionally replace values in a column.

 

= Table.ReplaceValue(#"Filtered Rows",each [CATEGORY DETAIL],each if ([CATEGORY]="CAR" and Text.Contains([PRODUCTS],"@"))=true then "BLUE CAR" else if [CATEGORY]="CAR" and Text.Contains([PRODUCTS],"@")=false then "RED CAR" else [CATEGORY DETAIL],Replacer.ReplaceText,{"CATEGORY DETAIL"})

 

Example of entries are

CATEGORY: CAR

PRODUCTS: This is a car@

CATEGORY DETAIL: random text

 

Does anyone know why the conditional replacement does not work?

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @dats ,

syntax looks alright to me at first sight.
Please be aware that Power Query is case sensitive.

Also, you could try the change the replacer function from Replacer.ReplaceText  to Replacer.ReplaceValue.

Also, make sure to clean and trim the CATEGORY-column.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi, @dats 

I have done test with the data and M code you provided. It works well.

Is the dashboard working well a live page pinned to it and the one with no changes a visual pinned it?

 

Best Regards,

Caiyun Zheng

ImkeF
Community Champion
Community Champion

Hi @dats ,

syntax looks alright to me at first sight.
Please be aware that Power Query is case sensitive.

Also, you could try the change the replacer function from Replacer.ReplaceText  to Replacer.ReplaceValue.

Also, make sure to clean and trim the CATEGORY-column.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

dats
Resolver I
Resolver I

@Greg_Deckler I don't think so. It worked in another dashboard with the exact same syntax which is why I am wondering that power bi doesn't replace the values accordingly nor returns an error

Greg_Deckler
Community Champion
Community Champion

@dats - Wouldn't you need a Replacer.ReplaceText for each of the if statements? And wouldn't you need to use all 3 arguments? @ImkeF 

Replacer.ReplaceText - PowerQuery M | Microsoft Docs



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors