Table.Buffer in Power Query: What It Does and How to Use It
In this article
Table.Buffer is a Power Query (M) function that loads a table into memory once and then reuses that single copy for every later step, instead of letting Power Query re-evaluate the source each time it is referenced. In practice you wrap a step in Table.Buffer() when a query feels slow, when a table is used more than once downstream, or when you need the order of rows to be locked in place. You do not need any add-in or licence: it works in the Power Query Editor inside Excel, Power BI Desktop and the Power Query web experience, and you can use it with no prior scripting knowledge as long as you are comfortable adding a step by hand.
What You'll Need
- A workbook in Excel (Windows or Mac) or a report in Power BI Desktop with at least one query loaded in the Power Query Editor. Menu names in the ribbon can differ slightly by version, edition and region.
- A query that already connects to a data source and has a few transformation steps applied, so there is something worth buffering.
- Basic familiarity with the Applied Steps list and the formula bar at the top of the editor.
- Ideally the Advanced Editor available (Home tab, in the Query section) so you can see the full M code, though the simple method below does not require it.
Step-by-Step
- Open the query in the Power Query Editor. In Excel, select a cell in the query output and use Data > Queries & Connections, then double-click the query, or use Data > Get Data to start a new one. In Power BI Desktop, use Home > Transform data. Confirm the ribbon shows the Home, Transform and Add Column tabs.
- Look at the Applied Steps pane on the right. Each transformation appears as a named step, and the last step is what the query returns. Note the name of the step you want to buffer, for example
Changed TypeorFiltered Rows. - Decide where the buffer belongs. Put it on the step whose result is reused, not automatically on the first step. If the whole query is slow and you only reference it once, buffering usually adds memory cost for no gain. Buffer the table that feeds a merge, an append across many files, or a step you reference several times.
- Add a custom step manually. Right-click the step you want to wrap and choose Insert Step After (or use the Add Step button in the ribbon), then in the formula bar type a name for the new step, an equals sign, and
Table.Buffer(followed by the previous step name and a closing bracket. For example, if the prior step is calledChanged Type, the code readsBuffered Table = Table.Buffer(#"Changed Type"). Keep the quote and hash characters exactly as they are. - Press Enter to commit. If the step name turns into a link in the Applied Steps list without an error message, the buffer is in place. The preview below the formula bar should show the same rows as before.
- Verify the step order matters. A buffer only freezes what has already happened. If you buffer before a filter, the filter still runs normally downstream; if you buffer before a sort, later operations keep the buffered order. Confirm the preview still matches what you expect before moving on.
- Check the full code once. Open Home > Advanced Editor and read the query top to bottom. Each step should reference the one before it, and the final
inline should return the last step, including your new buffered step. - Test performance with a refresh. Use Home > Refresh Preview to force a full evaluation rather than a cached preview. Compare how long the refresh takes and how much memory the query uses in Task Manager or Resource Monitor. Buffer changes can look good in preview and still cost memory on a large table.
- Clean up if it did not help. Right-click the buffered step and choose Delete to remove it. Removing a buffer step is safe; it only changes performance, never the returned data.
Common Mistakes
Buffering everything. Wrapping every step is the single most common error. Each buffer holds a full copy of the table in memory, so a long query can multiply memory use and slow the refresh instead of speeding it up. Buffer selectively, usually at the point where a table is referenced repeatedly.
Typing the previous step name wrong. Step names with spaces need quoting, and the hash character is required: #"Changed Type". Dropping the hash produces a syntax error, and using the column name instead of the step name produces a different, equally confusing error.
Expecting a buffer to fix a slow source. Table.Buffer does not make the original connection faster or cache it between refreshes. It only avoids re-evaluating within a single refresh. A slow database query is still slow the first time it runs.
Buffering a table that is still being expanded. If a step is waiting on another query, buffering too early can hold an incomplete or expanded result in memory. Put the buffer after the expansion steps, not before.
Assuming it is a permanent cache. The buffered copy is discarded when the query finishes refreshing. The next refresh starts from scratch, so do not rely on a buffer for persistence.
Tips
- Buffer the small side of a merge or join if you cannot buffer the large one; it often gives most of the speed benefit for a fraction of the memory.
- Name the step something readable like
Buffered Customersso the intent stays clear months later. - Buffer upstream of steps that repeatedly rescan the table, such as a
Table.AddColumnusing a lookup, or an index-based comparison. Repeated scans are where the biggest gains usually appear. - When loading many files from a folder, buffering the combined result after the file expansion often helps more than buffering the file list.
- Keep an eye on memory in Power BI Desktop while testing. If memory climbs sharply with no speed gain, the buffer is on the wrong step.
Troubleshooting
"There weren't enough elements in the enumeration" or a token error. The formula bar text is malformed. Check the hash and quotes around the step name, and confirm the parentheses close.
The query refreshes but is no slower or faster. The buffer is probably on a step that is evaluated only once anyway. Move it to the step feeding a merge, append or repeated lookup, or remove it.
Memory use spikes or Desktop becomes unresponsive. The buffered table is too large. Delete the step, or buffer a smaller filtered subset before the heavy step rather than the full table.
The preview looks right but the loaded table is wrong. Check the in line of the Advanced Editor still returns the final step, and that no buffer was inserted before a sort or filter you rely on. Refresh the preview fully with Home > Refresh Preview.
The step refuses to be inserted. Make sure you are not editing the first step, which has no previous step, and that the query is not in the middle of another edit. Close any open dialog and try again.
If that did not work, delete the buffer step, save and reopen the file, and rebuild the step by copying the previous step's name directly from the Applied Steps pane to avoid typos. If performance is still poor, the bottleneck is likely the source connection or a heavy transformation, not caching.
Frequently Asked Questions
Does Table.Buffer change my data?
No. It returns the same rows and columns. It only changes how many times the expression is evaluated.
Is Table.Buffer available in Excel and Power BI?
Yes, it is a standard M function in the Power Query engine used by both, and it is also available in the Power Query web experience. The exact menu labels around it can vary by version.
Should I buffer every query?
No. Buffer the tables that are referenced more than once or that are re-scanned by later steps. Buffering everything raises memory use for little benefit.
Does the buffer persist between refreshes?
No. The in-memory copy exists only while the query evaluates. Each refresh rebuilds it.
Can Table.Buffer speed up a slow folder of files?
Sometimes. Buffering the combined table after expansion can help when later steps rescan it, but the initial read of every file still happens each refresh.
What is the difference between Table.Buffer and Table.StopFolding?
Table.Buffer loads the table into memory, which also ends query folding for that branch. Table.StopFolding only stops folding, without necessarily materialising the table. Use Buffer when you want the data cached in memory, and StopFolding when you just want to control which steps are sent to the source.