Forum Discussion
Anonymous
4 years agoNot applicable
Merge Query against a range
Hi All, I am trying to find an efficient design pattern to do a merge join in Power Query where the join is not a striaght forward equality join. I have a table containing sales data and for ...
Vijay_A_Verma
4 years agoMost Valuable Professional
I have made 2 queries - One based on list approach and one based on Table.SelectRows approach.
This is a mini-mockup which you can fit in your code.
These will definitely improve performance. Let me know whether the improvement is acceptable or not/
The Excel mockup is uploaded to https://1drv.ms/x/s!Akd5y6ruJhvhuT0ZjSMjlq22TTQZ?e=AkZ7gr
let
Source = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product SKU", Int64.Type}, {"SalesDate", type date}}),
StartDateList = List.Buffer(ProductCostLookup[Start Date]),
EndDateList = List.Buffer(ProductCostLookup[End Date]),
CostList = List.Buffer(ProductCostLookup[Cost]),
SKUList = List.Buffer(ProductCostLookup[Product SKU]),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Cost", each CostList{List.PositionOf(List.Transform(List.Positions(StartDateList),(i)=>[SalesDate]>=StartDateList{i} and [SalesDate]<=EndDateList{i} and [Product SKU]=SKUList{i}),true)})
in
#"Added Custom"
Table.SelectRows approach
let
Source = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product SKU", Int64.Type}, {"SalesDate", type date}}),
BufferedTable = Table.Buffer(ProductCostLookup),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Cost", each Table.SelectRows(BufferedTable, (x)=> x[Start Date]<=[SalesDate] and x[End Date]>=[SalesDate] and x[Product SKU]=[Product SKU]){0}[Cost])
in
#"Added Custom"
- Anonymous4 years agoNot applicable
Thanks a lot for the code. I have implemented it but it is still very slow.