Hi all,
I am doing a VLOOKUP in Power Query, Data and Lookup tables attached, code below.
(taken from this post by Ken P: http://www.excelguru.ca/blog/2015/01/28/creating-a-vlookup-function-in-power-query/)
The data table is around 10,000 rows, and that's what I end up with in my query. However, when loading it shows around 1.3m rows loading and takes an age to load.
It uses a fuzzy match, as the lookup table works off code ranges.
Does anyone have an idea why this might be?
Thanks
Rich
I am doing a VLOOKUP in Power Query, Data and Lookup tables attached, code below.
(taken from this post by Ken P: http://www.excelguru.ca/blog/2015/01/28/creating-a-vlookup-function-in-power-query/)
The data table is around 10,000 rows, and that's what I end up with in my query. However, when loading it shows around 1.3m rows loading and takes an age to load.
It uses a fuzzy match, as the lookup table works off code ranges.
Does anyone have an idea why this might be?
Thanks
Rich
Code:
let VLOOKUP_AC = (lookup_value as any, table_array as table, col_index_number as number, optional approximate_match as logical ) as any =>
let
/*Provide optional match if user didn't */
matchtype =
if approximate_match = null
then true
else approximate_match,
/*Get name of return column */
Cols = Table.ColumnNames(table_array),
ColTable = Table.FromList(Cols, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ColName_match = Record.Field(ColTable{0},"Column1"),
ColName_return = Record.Field(ColTable{col_index_number - 1},"Column1"),
/*Find closest match */
SortData = Table.Sort(table_array,{{ColName_match, Order.Descending}}),
RenameLookupCol = Table.RenameColumns(SortData,{{ColName_match, "Lookup"}}),
RemoveExcess = Table.SelectRows(RenameLookupCol, each [Lookup] <= lookup_value),
ClosestMatch=
if Table.IsEmpty(RemoveExcess)=true
then "#N/A"
else Record.Field(RemoveExcess{0},"Lookup"),
/*What should be returned in case of approximate match? */
ClosestReturn=
if Table.IsEmpty(RemoveExcess)=true
then "#N/A"
else Record.Field(RemoveExcess{0},ColName_return),
/*Modify result if we need an exact match */
Return =
if matchtype=true
then ClosestReturn
else
if lookup_value = ClosestMatch
then ClosestReturn
else "#N/A"
in Return
in VLOOKUP_AC