Forum Discussion
Bulk replace in M language
- 4 years ago
Here is the solution based on Fuzzy matching with a sensitivity of 0.5. Download example file from https://1drv.ms/x/s!Akd5y6ruJhvhuTWHGs0sOgEVhYHd?e=3nFBvL
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([Data], "-")), #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Filtered Rows", {{"Data", each Text.BeforeDelimiter(_, "-"), type text}}), #"Removed Duplicates" = Table.Distinct(#"Extracted Text Before Delimiter"), #"Merged Queries" = Table.FuzzyNestedJoin(Source, {"Data"}, #"Removed Duplicates", {"Data"}, "Removed Duplicates", JoinKind.LeftOuter, [IgnoreCase=true, IgnoreSpace=true, NumberOfMatches=1, Threshold=0.5]), #"Expanded Removed Duplicates" = Table.ExpandTableColumn(#"Merged Queries", "Removed Duplicates", {"Data"}, {"Removed Duplicates.Data"}) in #"Expanded Removed Duplicates"
You can use following in a custom column and then delete the original column
try Text.Start([Project],Text.PositionOf([Project],"-")) otherwise [Project]For column inplace replace, use following code (change Source with your last step)
Table.ReplaceValue(Source,each [Project], each try Text.Start([Project],Text.PositionOf([Project],"-")) otherwise [Project], Replacer.ReplaceValue,{"Project"})
- irishguurl4 years agoNew Member
I believe I can replace the -water and -sewer part through the replace option in the tool bar. What complicates things is the base name of the project differs. See example below:
U0143 Radio Repeater P/C-Sewer
U0143 Radio Repeater P/C-Water
U0143 Radio Repeater Power/Comm
Ideally, I would want U0143 Radio Repeater Power/Comm to be the project name for all 3 versions. Does that make more sense? This issue occurs for many projects.
- Vijay_A_Verma4 years agoMost Valuable Professional
Either we need a list of replacement words or some convention to identify...For example -
U0133 SCADA at LLV-Sewer
U0133 SCADA at LLV-Water
U0133 SCADA Upgrades at Lake LVWhether name will be U0133 SCADA Upgrades at Lake LV or U0133 SCADA at LLV
U0171 Via Nobila Utilities
U0171 Via Nobila-Sewer
U0171 Via Nobila-WaterWhat will name will it be U0171 Via Nobila or U0171 Via Nobila Utilities?
- irishguurl4 years agoNew Member
I think it would be easier to replace with whatever is before the -water or -sewer. So in the case of the examples you show, it would be U0133 SCADA at LLV and U0171 Via Nobila.