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"
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 LV
Whether 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-Water
What will name will it be U0171 Via Nobila or U0171 Via Nobila Utilities?
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.
- Vijay_A_Verma4 years agoMost Valuable Professional
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"