Forum Discussion
Jeffrey T
Dec 15, 2022Copper Contributor
Find and replace comma separated values
Hello Everyone, I was provided an Excel sheet that has users in one column and the companies they belong to in another column, some with more than one group. username company john.smit...
flexyourdata
Dec 15, 2022Iron Contributor
You can try using the Fuzzy matching option in the Merge Queries function in Power Query.
I created two queries for your tables - data and lookup (respectively).
Then this:
let
Source = data,
split
= Table.ExpandListColumn(
Table.TransformColumns(
Source,
{{"company", Splitter.SplitTextByDelimiter(", ")}}),
"company"
),
fuzzy
= Table.FuzzyNestedJoin(
split,{"company"},
lookup, {"CompanyName"},
"lookup",
JoinKind.LeftOuter,
[IgnoreCase=true, IgnoreSpace=true, NumberOfMatches=1, Threshold=0.5]
),
expand
= Table.ExpandTableColumn(
fuzzy,
"lookup",
{"CompanyCode", "CompanyName"},
{"CompanyCode", "CompanyName"}
),
mergedcompany
= Table.AddColumn(
expand,
"mergedCompanyName",
each if [CompanyName] = null then [company] else [CompanyName]
),
group
= Table.Group(
mergedcompany,
{"username"},
{
{"Original", each Text.Combine([company],", ")},
{"Replaced", each Text.Combine([mergedCompanyName],", ")}
}
)
in
group
This is what the result looks like: