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

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

Reply
Anonymous
Not applicable

M code optimization

Hello

I would like to optimize the code of power query when I do search / replace

In a date field I process 3 types of modifications in a row and I would like to make these 3 modifications on a single line of code

 

#"Filtered rows4" = Table.SelectRows(#"Replaced errors", each true),

 

#"Replaced Value3" = Table.ReplaceValue(#"Filtered Lines4",null, "12/31/2050",Replace.ReplaceValue,{"Theoretical Date Lease End"}),

 

#"ReplacedValue4" = Table.ReplaceValue(#"ReplacedValue3", "SO", "12/31/2050",Replacer.ReplaceText,{"Theoretical End of Lease Date"}),

 

#"Replaced Value5" = Table.ReplaceValue(#"Replaced Value4", "cf SM", "12/31/2050",Replacer.ReplaceText,{"Theoretical Date Lease End"}),

 

#"Replaced Value6" = Table.ReplaceValue(#"Replaced Value5", "cf CAS", "12/31/2050",Replacer.ReplaceText,{"Theoretical Date Lease End"}),

 

My proposal that doesn't work for the moment

= List.ReplaceValue(#"ReplacedValue3", "SO", "cf CAS", "cf SM", "31/12/2050",Replacer.ReplaceText,{"Theoretical End of Lease Date"})

 

Obviously it only takes my 3 fields to replace

Thanks for your help

 

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

#"Filtered rows4" = Table.SelectRows(#"Replaced errors", each true),

this line is nothing but gibberish.

 

#"Replaced Value3" = Table.ReplaceValue(#"Filtered Lines4",each [Theoretical Date Lease End], each if List.Contains({null, "cf CAS", "cf SM"}, [Theoretical Date Lease End]) then "12/31/2050" else [Theoretical Date Lease End], Replace.ReplaceValue, {"Theoretical Date Lease End"}),

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Fowmy
Super User
Super User

@Anonymous 

You add the following step after #"Filtered rows4" step

 Table.TransformColumns(#"Filtered Lines4", {{"Channel", each if List.Contains({"SO", "cf CAS", "cf SM"},_) then "12/31/2050" else _, type text}})

  

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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