Power Query slows down after merging queries or tables

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
80
Hi All,

I'm experiencing a problem where power query slowed down after I merged two tables. Since the merge, each time I do a step, it appears its recalculating or refreshing something in the back ground. the refresh stops when it reaches 120MB which takes about 5 to 10 minutes. So basically each time I add a new step I have to wait 5 to 10 minutes before I can move forward.

One table has 700,000 rows X 30 columns and the other table had 150,000 x 30.

It took me almost an entire day to get 3/4 through what is needed for the end result.

The file was working fine up until I did the merge.

I've come across solutions suggesting that creating a primary key may be helpful but I've not seen any instructions on how to do this. I have a unique ID field that I can assign as primary key if needed.

I would really like some assistance with this as it is taking me forever to finish my query.

Thanks.
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

peter789

Board Regular
Joined
Nov 20, 2016
Messages
114
When developing the code for your query it is always possible to filter the data in the source queries first to a smaller subset. When it's all working fine delete the filters.

Peter
 

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
80
Her is my code. There are two main queries I'm using Current Year and Prior Year.
At the end, I try to merge Current Year with the Prior Year to get some new fields created in the Current Year file


Prior Year Query code

let
Source = Folder.Files("C:\Users\..........................."),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from Prior Year", each #"Transform File from Prior Year"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Prior Year"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Prior Year", Table.ColumnNames(#"Transform File from Prior Year"(#"Sample File"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Common System Number", Int64.Type}, {"System Number", Int64.Type}, {"Old System Number", type text}, {"Company", type text}, {"Activity Code", type text}, {"G/L Asset Account", Int64.Type}, {"Vendor", type any}, {"Description", type text}, {"Acquisition Date", type date}, {"Placed-in-Service Date", type date}, {"Current Through Date", type date}, {"Disposal Date", type date}, {"Current Remaining Life", Int64.Type}, {"Depreciation Method", type text}, {"Estimated Life", Int64.Type}, {"Acquisition Value", type number}, {"Current Accum", type number}, {"Net Book Value", type number}, {"Depreciation This Run", type number}, {"Location", type text}, {"Project Code", type text}}),
#"Filtered for Active only" = Table.SelectRows(#"Changed Type", each [Activity Code] = "A"),
#"Remeved Dep exp = 0" = Table.SelectRows(#"Filtered for Active only", each [Depreciation This Run] <> 0),
#"Added Custom" = Table.AddColumn(#"Remeved Dep exp = 0", "Period", each "FY 2018"),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Location"}, Location_Table, {"Location"}, "Location_Table", JoinKind.LeftOuter),
#"Expanded Location_Table" = Table.ExpandTableColumn(#"Merged Queries", "Location_Table", {"Type"}, {"Location_Table.Type"}),
#"Merged Queries1" = Table.NestedJoin(#"Expanded Location_Table", {"Common System Number"}, #"Current Year", {"Common System Number"}, "Current Year", JoinKind.LeftOuter)
in
#"Merged Queries1"


Current Year Query code

let
Source = Folder.Files("C:\Users\................"),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from Current Year", each #"Transform File from Current Year"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Current Year"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Current Year", Table.ColumnNames(#"Transform File from Current Year"(#"Sample File (2)"))),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Common System Number", Int64.Type}, {"System Number", Int64.Type}, {"Old System Number", type text}, {"Company", type text}, {"Activity Code", type text}, {"G/L Asset Account", Int64.Type}, {"Vendor", type text}, {"Description", type text}, {"Acquisition Date", type date}, {"Placed-in-Service Date", type date}, {"Current Through Date", type date}, {"Disposal Date", type date}, {"Current Remaining Life", Int64.Type}, {"Depreciation Method", type text}, {"Estimated Life", Int64.Type}, {"Acquisition Value", type number}, {"Current Accum", type number}, {"Net Book Value", type number}, {"Depreciation This Run", type number}, {"Location", type text}, {"Project Code", type text}, {"Reason for Disposal", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Activity Code] = "A" or [Activity Code] = "D"),
#"Custom Column to determine which Disposed items shodul be deleted" = Table.AddColumn(#"Filtered Rows", "Disposed item to delete", each if[Activity Code]="D" and [Disposal Date]< Disposal_Cutoff_Date then "Delete" else "Do not Delete"),
#"Delete some disposed items" = Table.SelectRows(#"Custom Column to determine which Disposed items shodul be deleted", each [Disposed item to delete] <> "Delete"),
#"Merged Queries" = Table.NestedJoin(#"Delete some disposed items", {"Common System Number"}, #"Prior Year Expense", {"Common System Number"}, "Prior Year Expense", JoinKind.LeftOuter),
#"Added Prior Year Expense" = Table.ExpandTableColumn(#"Merged Queries", "Prior Year Expense", {"Depreciation This Run"}, {"Prior Year Expense.Depreciation This Run"}),
#"Added Custom column for Disp items with no PY exp" = Table.AddColumn(#"Added Prior Year Expense", "Disposed items with do exp in PY", each if[Activity Code] = "D" and [Prior Year Expense.Depreciation This Run] = null then "Delete" else "Do not Delete"),
#"Filtered Rows2" = Table.SelectRows(#"Added Custom column for Disp items with no PY exp", each [Disposed items with do exp in PY] = "Do not Delete"),
#"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "Coding", each if[Activity Code]="D" then "Disposals"
else if [Activity Code]="A" and [Depreciation This Run]=0 and [Prior Year Expense.Depreciation This Run]<>0 then "Fully Depreciated"
else if [Activity Code] = "A" and [Acquisition Date]>= Additions_Prior_Year_Date then "Additions"
else if [Activity Code] = "A" and [Acquisition Date] >= Catchup_Depreciation_Date_Start and [Acquisition Date] <= Catchup_Depreciation_Date_End and [#"Placed-in-Service Date"]<catchup_depreciation_date_start then="" "catchup="" depreciation"="" else="" "still="" depreciating"),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom1", "New Depreciation this Run", each if [Activity Code] = "A" then [Depreciation This Run] else 0),
#"Added Custom" = Table.AddColumn(#"Added Conditional Column", "Period", each "FY 2019"),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Final Delete", each if[Coding] = "Still Depreciating" and [Depreciation This Run]=0 then "Delete" else "Do not Delete"),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each [Final Delete] = "Do not Delete"),
#"Merged Queries1" = Table.NestedJoin(#"Filtered Rows1", {"Location"}, Location_Table, {"Location"}, "Location_Table", JoinKind.LeftOuter),
#"Expanded Location_Table" = Table.ExpandTableColumn(#"Merged Queries1", "Location_Table", {"Type"}, {"Location_Table.Type"})
in
#"Expanded Location_Table"</catchup_depreciation_date_start>
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,744
could you edit your post and use CODE tags?

you've 10 minutes from time of your post: 06:43 PM - 06:53 PM
 
Last edited:

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
80
Peter, do you mind expanding a bit on how best to do this? I tried it, however so much information was filtered out that I was not able to verify along the way if my steps were correct as too much info was already filtered out.

Also, when rows or columns are filtered out, does the query reduce in size? example, if my original query is stating 50MB in size when its refreshing, if I filter out the half the rows and column, would the query drop in size say to 25MB.

I've been trying to test this but unable to see how, I only know the size when its taking forever to refresh update and you see how long it ave remaining.
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,744
which query is slow? first or second?

you said you add a KEY but I don't see that
 
Last edited:

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
80
How do I use key tags?

The primary key is not in this code. I was trying it after the query kept slowing down but I was not able to save it because of how long it took.
 

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
80
Both Queries are slow. The Current Year was the slowest at first, however when I completed the current year and merged it with Prior year as then needed a field from the Current Year, the Prior Year got really really slow.

Prior Year Query code


let
Code:
[COLOR=#333333]Source = Folder.Files("C:\Users\..........................."),[/COLOR]
[COLOR=#333333]#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),[/COLOR]
[COLOR=#333333]#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from Prior Year", each #"Transform File from Prior Year"([Content])),[/COLOR]
[COLOR=#333333]#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),[/COLOR]
[COLOR=#333333]#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Prior Year"}),[/COLOR]
[COLOR=#333333]#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Prior Year", Table.ColumnNames(#"Transform File from Prior Year"(#"Sample File"))),[/COLOR]
[COLOR=#333333]#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Common System Number", Int64.Type}, {"System Number", Int64.Type}, {"Old System Number", type text}, {"Company", type text}, {"Activity Code", type text}, {"G/L Asset Account", Int64.Type}, {"Vendor", type any}, {"Description", type text}, {"Acquisition Date", type date}, {"Placed-in-Service Date", type date}, {"Current Through Date", type date}, {"Disposal Date", type date}, {"Current Remaining Life", Int64.Type}, {"Depreciation Method", type text}, {"Estimated Life", Int64.Type}, {"Acquisition Value", type number}, {"Current Accum", type number}, {"Net Book Value", type number}, {"Depreciation This Run", type number}, {"Location", type text}, {"Project Code", type text}}),[/COLOR]
[COLOR=#333333]#"Filtered for Active only" = Table.SelectRows(#"Changed Type", each [Activity Code] = "A"),[/COLOR]
[COLOR=#333333]#"Remeved Dep exp = 0" = Table.SelectRows(#"Filtered for Active only", each [Depreciation This Run] <> 0),[/COLOR]
[COLOR=#333333]#"Added Custom" = Table.AddColumn(#"Remeved Dep exp = 0", "Period", each "FY 2018"),[/COLOR]
[COLOR=#333333]#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Location"}, Location_Table, {"Location"}, "Location_Table", JoinKind.LeftOuter),[/COLOR]
[COLOR=#333333]#"Expanded Location_Table" = Table.ExpandTableColumn(#"Merged Queries", "Location_Table", {"Type"}, {"Location_Table.Type"}),[/COLOR]
[COLOR=#333333]#"Merged Queries1" = Table.NestedJoin(#"Expanded Location_Table", {"Common System Number"}, #"Current Year", {"Common System Number"}, "Current Year", JoinKind.LeftOuter)[/COLOR]
[COLOR=#333333]in[/COLOR]
[COLOR=#333333]#"Merged Queries1"[/COLOR]

Current Year Query code

let
Code:
[COLOR=#333333]Source = Folder.Files("C:\Users\................"),[/COLOR]
[COLOR=#333333]#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),[/COLOR]
[COLOR=#333333]#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File from Current Year", each #"Transform File from Current Year"([Content])),[/COLOR]
[COLOR=#333333]#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),[/COLOR]
[COLOR=#333333]#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from Current Year"}),[/COLOR]
[COLOR=#333333]#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from Current Year", Table.ColumnNames(#"Transform File from Current Year"(#"Sample File (2)"))),[/COLOR]
[COLOR=#333333]#"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"Common System Number", Int64.Type}, {"System Number", Int64.Type}, {"Old System Number", type text}, {"Company", type text}, {"Activity Code", type text}, {"G/L Asset Account", Int64.Type}, {"Vendor", type text}, {"Description", type text}, {"Acquisition Date", type date}, {"Placed-in-Service Date", type date}, {"Current Through Date", type date}, {"Disposal Date", type date}, {"Current Remaining Life", Int64.Type}, {"Depreciation Method", type text}, {"Estimated Life", Int64.Type}, {"Acquisition Value", type number}, {"Current Accum", type number}, {"Net Book Value", type number}, {"Depreciation This Run", type number}, {"Location", type text}, {"Project Code", type text}, {"Reason for Disposal", type text}}),[/COLOR]
[COLOR=#333333]#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Activity Code] = "A" or [Activity Code] = "D"),[/COLOR]
[COLOR=#333333]#"Custom Column to determine which Disposed items shodul be deleted" = Table.AddColumn(#"Filtered Rows", "Disposed item to delete", each if[Activity Code]="D" and [Disposal Date]< Disposal_Cutoff_Date then "Delete" else "Do not Delete"),[/COLOR]
[COLOR=#333333]#"Delete some disposed items" = Table.SelectRows(#"Custom Column to determine which Disposed items shodul be deleted", each [Disposed item to delete] <> "Delete"),[/COLOR]
[COLOR=#333333]#"Merged Queries" = Table.NestedJoin(#"Delete some disposed items", {"Common System Number"}, #"Prior Year Expense", {"Common System Number"}, "Prior Year Expense", JoinKind.LeftOuter),[/COLOR]
[COLOR=#333333]#"Added Prior Year Expense" = Table.ExpandTableColumn(#"Merged Queries", "Prior Year Expense", {"Depreciation This Run"}, {"Prior Year Expense.Depreciation This Run"}),[/COLOR]
[COLOR=#333333]#"Added Custom column for Disp items with no PY exp" = Table.AddColumn(#"Added Prior Year Expense", "Disposed items with do exp in PY", each if[Activity Code] = "D" and [Prior Year Expense.Depreciation This Run] = null then "Delete" else "Do not Delete"),[/COLOR]
[COLOR=#333333]#"Filtered Rows2" = Table.SelectRows(#"Added Custom column for Disp items with no PY exp", each [Disposed items with do exp in PY] = "Do not Delete"),[/COLOR]
[COLOR=#333333]#"Added Custom1" = Table.AddColumn(#"Filtered Rows2", "Coding", each if[Activity Code]="D" then "Disposals" [/COLOR]
[COLOR=#333333]else if [Activity Code]="A" and [Depreciation This Run]=0 and [Prior Year Expense.Depreciation This Run]<>0 then "Fully Depreciated"[/COLOR]
[COLOR=#333333]else if [Activity Code] = "A" and [Acquisition Date]>= Additions_Prior_Year_Date then "Additions"[/COLOR]
[COLOR=#333333]else if [Activity Code] = "A" and [Acquisition Date] >= Catchup_Depreciation_Date_Start and [Acquisition Date] <= Catchup_Depreciation_Date_End and [#"Placed-in-Service Date"][/COLOR]<catchup_depreciation_date_start then="" "catchup="" depreciation"="" else="" "still="" depreciating"),
 #"Added Conditional Column" = Table.AddColumn(#"Added Custom1", "New Depreciation this Run", each if [Activity Code] = "A" then [Depreciation This Run] else 0),
#"Added Custom" = Table.AddColumn(#"Added Conditional Column", "Period", each "FY 2019"),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Final Delete", each if[Coding] = "Still Depreciating" and [Depreciation This Run]=0 then "Delete" else "Do not Delete"),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each [Final Delete] = "Do not Delete"),
#"Merged Queries1" = Table.NestedJoin(#"Filtered Rows1", {"Location"}, Location_Table, {"Location"}, "Location_Table", JoinKind.LeftOuter),
#"Expanded Location_Table" = Table.ExpandTableColumn(#"Merged Queries1", "Location_Table", {"Type"}, {"Location_Table.Type"})
in
#"Expanded Location_Table</catchup_depreciation_date_start>
 
Last edited:

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,744
so try for Prior as first line in the code (after let before Source of course)

Key = Table.AddKey(#"Added Custom", {"Location"}, true),

for Current

Key = Table.AddKey(#"Delete some disposed items", {"Common System Number"}, true),

if it doesn't work faster try Key for: #"Merged Queries1"
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,102,021
Messages
5,484,236
Members
407,436
Latest member
smurfkings247

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top