Troubleshooting “Out of Memory” during the SQL “Fold-to-Data-Source” phase.

The error “Evaluation ran out of memory” or “System.OutOfMemoryException” during the SQL “Fold-to-Data-Source” phase occurs when Power Query’s Mashup Engine evaluates transformation steps to generate a native SQL query, but exhausts the available system RAM before it can send the query to the server. Instead of the database server running out of memory, this failure happens locally on your computer inside the evaluation container (Microsoft.Mashup.Container.NetFX45.exe) when query logic becomes too complex for the engine to translate efficiently into SQL.

Quick Answer

To fix “Out of Memory” errors during the SQL fold-to-data-source phase, rewrite your initial transformation steps to maintain query folding, or bypass the client-side Mashup Engine entirely by placing an explicit SQL statement inside the Native Database Query box. Additionally, ensure you are running 64-bit Excel to remove the 2GB virtual memory cap imposed on 32-bit processes.


How the “Fold-to-Data-Source” Phase Consumes Memory

When you build transformations in Power Query—such as filtering rows, grouping categories, or calculating new columns—the engine uses a mechanism called Query Folding. Query folding translates your Power Query M steps into a single, optimized SQL SELECT statement that executes directly on the remote database server.

Before sending that query, the Mashup Engine analyzes your sequence of steps from start to finish to determine how much logic can be translated. This is the Fold-to-Data-Source phase.

Memory exhaustion occurs during this phase when:

  1. Folding Breaks Early: If an early transformation cannot be translated into SQL (for example, a complex custom text function), Power Query must download the entire untranslated dataset into local workstation RAM to perform the remaining steps locally.
  2. Cyclic or Conflicting Step Logic: When a query contains nested joins, repeated table references, or multiple sorting steps, the Mashup Engine generates an exponentially growing evaluation tree. The optimizer consumes gigabytes of memory attempting to construct the native query before sending a single network packet.
  3. 32-bit Excel Memory Limits: If you use 32-bit Excel, the entire Mashup Engine process is hard-capped at 2GB of virtual address space, regardless of how much physical RAM your computer has.

To understand why query folding breaks and how to inspect step status, read Troubleshooting “Query Folding” breaks: Why your SQL is running slow in Excel..


Practical Diagnostic and Repair Steps

Step 1: Bypass Mashup Optimization Using Native SQL

The fastest and most reliable way to eliminate out-of-memory errors during query planning is to write your own SQL statement directly in the connection setup. This instructs the Mashup Engine to bypass step-by-step query generation entirely.

  1. Open your workbook and launch the Power Query Editor.
  2. Click New Source > Database > SQL Server Database.
  3. In the connection window, enter your Server and Database.
  4. Expand the Advanced options section.
  5. In the SQL statement box, enter your pre-filtered and joined query: SELECT CustomerID, OrderDate, TotalDue FROM Sales.Orders WHERE OrderDate >= '2025-01-01'
  6. Click OK.

Because the query is already defined in clean SQL, Power Query skips the fold-generation phase and lets the database server handle all filtering and aggregation.

For troubleshooting large multi-table joins that hit memory ceilings, refer to Handling “Evaluation ran out of memory” when joining massive SQL tables..

Step 2: Reorder Transformation Steps to Restore Folding

If you prefer building queries using Power Query’s graphical interface rather than writing raw SQL, reorganize your steps so the database engine does the heavy filtering before any client-side transformations occur.

  1. Open the Power Query Editor and select your failing query.
  2. In the Applied Steps pane on the right, inspect each step:
    • Right-click each step from top to bottom and look at View Native Query.
    • As long as View Native Query is clickable (black text), that step is folding to the database.
    • The first step where View Native Query is greyed out marks where folding broke.
  3. Move non-folding operations (such as custom columns, manual type conversions, or custom split-by-delimiter logic) to the very end of the step list.
  4. Ensure row filters (Table.SelectRows) and column removals (Table.SelectColumns) occur immediately after the Navigation step. This minimizes the volume of data evaluated by subsequent steps.

Step 3: Clear the Local Power Query Cache

During complex query development, Power Query writes evaluation traces and intermediate data snapshots to a local cache folder on your hard drive. If this cache becomes corrupted or bloated, the evaluation process can run out of memory immediately upon opening a query.

  1. In Excel, go to File > Options and settings > Query Options (or Data > Get Data > Query Options).
  2. Under the Global heading in the left pane, click Data Load.
  3. Scroll down to the Data Cache Management Options section.
  4. Click Clear Cache.
  5. Under Cache size, verify that the maximum allowed size is adequate (at least 4096 MB).
  6. Click OK, then restart Excel.

Hardware and Architecture Checks

If query reordering and native SQL do not resolve the memory crash: