Created
May 23, 2023 16:05
-
-
Save ncalm/32b605076076a6080522e768c10bb2d6 to your computer and use it in GitHub Desktop.
Power Query function for cleaning pairwise matches on an arbitrary column-set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Data as table, ComparisonColumns as list, ReplacementFunction as function) as table => | |
let | |
AddRecords = Table.AddColumn(Data, "Record",each _), | |
AddSortedComparisonValues = Table.AddColumn( | |
AddRecords, | |
"SortedComparisonValues", | |
each List.Sort( | |
Record.FieldValues( | |
Record.SelectFields(_, ComparisonColumns) | |
) | |
) | |
), | |
GetReplacement = Table.Group( | |
AddSortedComparisonValues, | |
"SortedComparisonValues", | |
{ | |
{"ReplacementRecord", | |
each ReplacementFunction(Table.SelectColumns(_, ComparisonColumns))} | |
} | |
), | |
AddReplacementRecord = Table.AddColumn( | |
AddSortedComparisonValues, | |
"ReplacementRecord", | |
each GetReplacement{ | |
[SortedComparisonValues=[SortedComparisonValues]] | |
}[ReplacementRecord] | |
), | |
RecordMerge = Table.AddColumn( | |
AddReplacementRecord, | |
"NewRecord", | |
each [Record] & [ReplacementRecord] | |
), | |
Result = Table.FromRecords(RecordMerge[NewRecord]) | |
in | |
Result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment