Forum Discussion
TestssonNow
2 years agoNew Member
Translate index match in Excel Power Query
Hi! It is too heavy for Excel to execute the function =index(a:a, match(true, exact(b2, c:c), 0)) for +800 rows. I thus want to do this via Power Query in Excel instead (I loaded the data using g...
ronrsnfld
2 years agoSuper User
Using a similar algorithm as m_dekorte , and generating a CSV file with 800,000 rows, and only single matches between Columns B & C, the PQ took about 15 seconds to run. (It took longer to write the results back to the Excel worksheet). I did not get any out of memory errors.
M-Code: Paste into Advanced Editor
let
//Change next line to reflect actual file path
Source = Csv.Document(File.Contents("C:\Users\ron\Documents\test.csv"),[Delimiter=",", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column A", type text}, {"Column B", Int64.Type}, {"Column C", Int64.Type}}),
//Add index column to be able to re-sort into original order
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
//Join the table to itself, using different columns for the "key"
#"Self-Join" = Table.NestedJoin(#"Added Index","Column B",#"Added Index","Column C","Index Match",JoinKind.LeftOuter),
//Expand the joined table Column A
#"Expanded Index Match" = Table.ExpandTableColumn(#"Self-Join", "Index Match", {"Column A"}, {"Index Match.Column A"}),
//Sort back to original order
#"Sorted Rows" = Table.Sort(#"Expanded Index Match",{{"Index", Order.Ascending}}),
//Remopve Index column
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"})
in
#"Removed Columns"
Partial Results
How much memory do you have?
Are you running Excel 32 bit or 64 bit?