Power Query slows down after merging queries or tables
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Power Query slows down after merging queries or tables
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Power Query slows down after merging queries or tables

    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.

  2. #2
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    2,678
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)

    Cool Re: Power Query slows down after merging queries or tables

    post M-code , use [CODE]your M-code here[/CODE]
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    impossible things we do on the spot. for miracles you need to wait for a while

  3. #3
    Board Regular
    Join Date
    Nov 2016
    Posts
    99
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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

  4. #4
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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"] #"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"

  5. #5
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    2,678
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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 by sandy666; Jul 4th, 2019 at 12:53 PM.
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    impossible things we do on the spot. for miracles you need to wait for a while

  6. #6
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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.

  7. #7
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    2,678
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)

    Cool Re: Power Query slows down after merging queries or tables

    which query is slow? first or second?

    you said you add a KEY but I don't see that
    Last edited by sandy666; Jul 4th, 2019 at 12:59 PM.
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    impossible things we do on the spot. for miracles you need to wait for a while

  8. #8
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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.

  9. #9
    Board Regular
    Join Date
    Apr 2014
    Posts
    80
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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:
    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
    Code:
    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"]
    Last edited by bobby_smith; Jul 4th, 2019 at 01:21 PM.

  10. #10
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    2,678
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Power Query slows down after merging queries or tables

    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 by sandy666; Jul 4th, 2019 at 01:42 PM. Reason: typos
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    impossible things we do on the spot. for miracles you need to wait for a while

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •