42 min read

Power Query Formula.Firewall: Fix Errors with M Templates

Fix Power Query Formula.Firewall errors with M templates. Check privacy levels and query partitions, then verify Desktop and service refresh.

Power Query Formula.Firewall: Fix Errors with M Templates

By jackey.ye · Updated 2026-11-27

A Formula.Firewall error means Power Query's Data Privacy Firewall stopped a query from being evaluated. It has two distinct variants: a partition that references other queries and accesses a data source, or a partition that touches data sources whose privacy levels can't be combined. One message names the structure, the other names the levels — and which one you have decides the repair.

Two messages cover almost every case, and they point to different repairs:

  • Formula.Firewall: Query 'Query1' (step 'Source') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

  • Formula.Firewall: Query 'Query1' (step 'Source') is accessing data sources that have privacy levels which cannot be used together. Please rebuild this data combination.

A partition is a group of one or more query steps; the smallest is a single step, and the largest can span several queries. The rule Microsoft documents is narrow: a partition may either access compatible data sources, or reference other partitions, but not both. Some products now relax that restriction, which is why the first variant doesn't automatically mean your structure is wrong — check the product note below before you refactor.

Which Formula.Firewall Error Variant Do You Have?

Read the message text first: "references other queries or steps" means one partition is both referencing another partition and hitting a data source, while "privacy levels which cannot be used together" means a single partition is touching sources whose levels are incompatible. The first is usually structural; the second is usually configuration. Run the triage in this order, and stop at the first match:

  1. Read the exact message and note which of the two variants it matches.

  2. List every source the query touches, then record each source's privacy level in Desktop and in the service.

  3. Decide whether the boundary is the problem — a partition mixing a reference with a source call — or the levels are the problem.

  4. Restructure the M only after you know which of the two you are fixing.

  5. Re-verify in Desktop with privacy checks on, then in the service and through the gateway.

Symptom you see

Likely cause

First move

Not the fix

Message says "references other queries or steps" on a build that supports the relaxation

A partition combines a cross-partition reference with direct source access

Confirm privacy levels are compatible, then split the query into source-only queries plus a combination query

Reformatting the M text, renaming steps, or adding a buffer

Message says "references other queries or steps" on an older build or a product without the relaxation

The same structural pattern, with no product-level allowance

Restructure the query boundaries, or move to a build that supports the pattern

Raising privacy levels just to silence the error

Message says "privacy levels which cannot be used together"

One partition touches sources whose levels cannot share, e.g. Private with Organizational

Set explicit, correct levels per source, then restructure if levels alone can't resolve it

Marking a sensitive source Public

Query refreshes in Desktop but fails in the service or via a gateway

Levels set in Desktop are not carried over, or the gateway applies its own

Re-check levels in Manage connections and gateways

Assuming the Desktop success proves the model is fixed

Error appears on a report that worked for months

Source metadata or evaluation changed the partition boundaries

Re-run the triage from step 1 with the current query

Editing until something stops throwing

Both rules exist because of folding. Folding converts M transformations into operations the data source runs, and Power Query may decide the most efficient plan is to take data from one source and pass it into another — for example, inlining a small CSV into a SQL statement so the database performs the join. That path is how a value marked Private can end up inside an external request. The firewall divides queries into partitions and replaces every cross-partition reference with a call to an internal function, Value.Firewall, so it can decide whether the data is allowed through. When a partition references another partition, the firewall must be the gatekeeper for everything flowing in; if that same partition also opens its own data source, incoming data could leak to it unnoticed, so the combination is blocked. Microsoft documents this partitioning logic in Behind the scenes of the Data Privacy Firewall.

Does the product relax the reference-plus-source restriction?

Sometimes. Microsoft's firewall article carries an explicit note that "this restriction is now relaxed in certain products" and links to a Power BI Desktop setting, Allow data privacy firewall partitions that reference other partitions to also access data sources (checked 2026-11-27). The setting's own page describes it as a preview feature under File > Options and settings > Options > GLOBAL > Preview features, states that it "lets Power Query evaluate query steps that reference other queries and access data sources when the involved data source privacy levels are compatible," and says it "doesn't disable the Data Privacy Firewall." It also notes that the same scenario "is already supported in the Power BI service," and that starting with the July 2026 version of Power BI Desktop the setting is enabled by default. If the setting isn't present, update Desktop; on older builds the older behavior applies.

See Allow data privacy firewall partitions that reference other partitions to also access data sources for the current wording, and treat the product you actually run as the authority rather than this article.

Triage rule: if the message names privacy levels, fix levels; if it names query references, check your build, the product, and the levels before restructuring M.

Should You Check Privacy Levels Before Touching the M Code?

Yes, and usually first. Some "references other queries" errors turn out to be compatibility problems, so checking levels is a sensible early step before you change any M code. Power Query classifies each source as None, Private, Organizational, or Public, and the table below is the only combination that can share a partition: sources that are both Public, or both Organizational. Private cannot fold into anything, and Public cannot mix with Organizational inside one partition.

Level

Folds into

Typical source

None

No privacy settings applied; use only in controlled development environments

Test copies, sandbox data

Private

Nothing — not even other Private sources

A text file of stock awards, a workbook of employee reviews

Organizational

Private and other Organizational sources; not Public

A Word document on an intranet SharePoint site limited to a trusted group

Public

Any other source

Wikipedia data, a local file copied from a public web page

Microsoft's privacy levels reference carries these definitions and the guidance to configure highly sensitive sources as Private. Note the asymmetry that causes most surprises: a Private source cannot fold into anything, so a Private workbook merged with an Organizational SQL table is blocked even though neither source is "wrong." The same page gives the concrete example of a Private workbook table merged with an Organizational SQL Server table being blocked because Private is more restrictive.

In Power BI Desktop, set levels at File > Options and settings > Data source settings, select the source, then Edit Permissions and choose a level under Privacy Levels. In Power Query Online, set the level in the connector's Get data dialog, or use Manage connections on the Home tab, edit the connection, choose the level and select Update. After either path, reopen the permissions or connection settings and confirm the level persisted — the service requires you to re-enter credentials before Save becomes available on an existing connection.

Here's the trap to avoid: don't downgrade a sensitive source to Public just because the error goes away. That marks internal warehouse data as world-readable for folding purposes and lets it be pulled into external requests, which is the exact leak the firewall was built to stop. If the levels genuinely can't be reconciled, the honest options are to restructure the query so incompatible sources never share a partition, to move the combination upstream into a governed layer that serves one source, or to document an approved exception with a named owner.

What Is the Cleanest Fix: Split Sources From the Combination?

The usual structural response is to stop one partition from doing both jobs. Put each data source access in its own source-only query, then build one combination query that only references those two queries and never calls a data source itself. Splitting the source access from the combination is a useful structural pattern to test. It doesn't guarantee a fix on its own: how Power Query partitions the queries, the connectors you use, the privacy levels involved, and your product version all shape whether the error clears.

Below is a complete, copyable pattern. It models a common real case: you have a local CSV of customer contracts (treated as Private) and a SQL table of customers, and you need a merged result. The CSV uses synthetic data so you can paste it straight into the Advanced Editor and see expected output.

Prerequisites

  • Two queries already exist or you'll create them as shown: src_ContractsCsv (CSV) and src_CustomersSql (SQL).

  • Replace the Sql.Database server and database arguments, the C:\data\contracts.csv path, and DimCustomers with your own values.

  • Set privacy levels deliberately on both sources: the CSV as Private (contract terms), SQL as Organizational.

  • The goal is a combination query that touches no data source directly.

Step 1 — source-only query: src_ContractsCsv

let
      // Synthetic sample; replace File.Contents with your real path or connector.
      Source = Csv.Document(
          File.Contents("C:\data\contracts.csv"),
          [Delimiter = ",", Columns = 4, Encoding = 65001, QuoteStyle = QuoteStyle.Csv]
      ),
      Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
      Typed = Table.TransformColumnTypes(
          Promoted,
          {{"CustomerID", type text}, {"ContractID", type text}, {"Status", type text}, {"Seats", Int64.Type}}
      )
  in
      Typed
  

Expected rows when you paste this sample CSV into C:\data\contracts.csv: 4 data rows (C001, C002, C003, C004). The sample file content is:

CustomerID,ContractID,Status,Seats
  C001,CTR-1001,Active,120
  C002,CTR-1002,Active,48
  C003,CTR-1003,Paused,300
  C004,CTR-1004,Active,15
  

Step 2 — source-only query: src_CustomersSql

let
      Source = Sql.Database("myserver.database.windows.net", "Sales"),
      DimCustomers = Source{[Schema = "dbo", Item = "DimCustomers"]}[Data],
      Selected = Table.SelectColumns(DimCustomers, {"CustomerID", "CustomerName", "Region"}),
      Typed = Table.TransformColumnTypes(
          Selected,
          {{"CustomerID", type text}, {"CustomerName", type text}, {"Region", type text}}
      )
  in
      Typed
  

Point Sql.Database at your own server and database. Set this source's privacy level to Organizational. Both step-1 and step-2 queries return tables and load nothing into the model themselves unless you enable load for them.

Step 3 — combination-only query: qry_CustomerContracts

let
      // References the two source queries by name. No data source access here.
      Contracts = src_ContractsCsv,
      Customers = src_CustomersSql,
      Joined = Table.NestedJoin(
          Contracts, {"CustomerID"},
          Customers, {"CustomerID"},
          "Customer", JoinKind.Inner
      ),
      Expanded = Table.ExpandTableColumn(
          Joined, "Customer", {"CustomerName", "Region"}, {"CustomerName", "Region"}
      ),
      Sorted = Table.Sort(Expanded, {{"Region", Order.Ascending}, {"CustomerName", Order.Ascending}})
  in
      Sorted
  

Expected rows with the sample CSV and a matching DimCustomers table containing C001–C004: 4 rows, columns CustomerID, ContractID, Status, Seats, CustomerName, Region. If your DimCustomers is missing one of those IDs, an inner join returns 3 rows — that's your signal to check the key, not the firewall.

Example configuration — validate in your target environment.

Why this helps and where caution is still needed. Separating each source access from the combination is meant to keep the decision points clear, but queries are not guaranteed to map one-to-one onto partitions, so how the engine partitions your queries can still differ from the file layout. Microsoft documents that references are wrapped in Value.Firewall even when a partition only references other partitions, so interception can still occur. Two further caveats matter. First, if you later add a reference inside src_CustomersSql or src_ContractsCsv while keeping the source call, you recreate the prohibited pattern. Second, this pattern addresses the structural variant; it does not make incompatible privacy levels compatible. The documented compatibility rule applies to sources sharing a single partition, and when a combination spans incompatible levels the engine may buffer the referenced partition — Private with Organizational is a common trigger, but not an automatic failure in every case. Test the pattern rather than assuming the error is gone.

Does Table.Buffer Fix a Privacy Firewall Error? Usually Not

No. Table.Buffer is a performance and evaluation tool, not a firewall permission. Microsoft's Table.Buffer reference states that "buffering is shallow" — it forces evaluation of scalar cell values but leaves records, lists, and nested tables as-is — and that using it "might or might not make your queries run faster," because "buffering prevents downstream folding" and adds the cost of reading all data into memory.

So treat it as a candidate, not a cure. A buffer placed on a small lookup table before a join can change evaluation order and occasionally clear a boundary issue, but it can also turn a fast folded query into a full table scan. If your intent is only to stop folding rather than to materialize data, the same page recommends Table.StopFolding instead. And if the actual problem is incompatible privacy levels, buffering won't reconcile them — you still have to fix the levels or change where the sources are combined.

My rule of thumb: fix the structure first, then measure. Add a buffer only when you can show the refresh got faster or the row counts stayed identical while a folding problem disappeared. Never present a buffer as a guarantee that Formula.Firewall will stop appearing.

Should You Wrap Reusable Queries in Functions?

Often yes, but understand what a function changes. Converting a referenced table query into a parameterless function and calling it with () at the reference site shifts where the partition boundary falls; it doesn't repeal the underlying rule. Practitioner guidance from Imke Feldmann's quick fix for Formula.Firewall issues describes the technique, but it is not Microsoft doctrine and the author notes it works in many cases but not all.

In the query holding the table to append, add a final step that wraps the previous step as a function with no parameters. Back in the consuming query, the reference now returns a function rather than a table, so append brackets to call it. Any query or model object that loaded that table directly will now break; restore it by adding a step at the end of the converted query that calls the function so it returns a table again. Verify the staging query still returns a table, the consuming query refreshes, and nothing that previously loaded the table now errors.

Prefer the split-source pattern above when you can. It's easier to explain in a review and doesn't depend on evaluation subtleties.

Do M Templates and Custom Functions Help or Hurt?

On their own they're neutral: the firewall reacts to partition structure, not to whether code lives inside a function. Used well, a function that encapsulates a single source access keeps that access in one partition and makes reuse clean, and a shared template that standardizes privacy-level assumptions across a team reduces the misconfiguration behind the second error variant. Used badly, a function that internally references another query and also calls a data source reproduces the exact pattern the firewall blocks — and because the violation sits inside the function body, it's harder to spot from the error text.

Decide with three rules:

  • Wrap in a function when the logic touches one source and you need it in several queries.

  • Split the access out when the logic combines a referenced query with a data source call, then let a combination query do the join.

  • Keep parameters separate where they feed a data source function directly. Parameter queries get trimmed into the calling partition during the static phase, which is why Web.Contents(myUrl) with a parameter behaves differently from a cross-query reference.

If your models pull from several lakehouse tables at once, the same logic scales: fewer distinct sources per partition means fewer level conflicts to resolve. Our lakehouse vs data warehouse notes for Power BI cover how that choice affects refresh paths, and the medallion implementation checklist is useful when you want one governed layer to feed the model instead of a dozen raw connections.

How Do You Make the Fix Survive Publishing and Scheduled Refresh?

Two things break overnight refreshes: privacy settings that don't carry over, and levels that the gateway applies on its own.

The first is documented asymmetry. Ignore the Privacy Levels and potentially improve performance does not work for semantic models. Reports built in Power BI Desktop with that setting and published to the Power BI service don't adhere to it, so a Desktop-only fix built on Fast Combine fails on refresh. Microsoft states this in the privacy levels reference, which also notes that privacy levels are available on the personal gateway.

On-premises sources add a second dimension. When a refresh runs through a gateway, privacy checks apply at the gateway, and levels for those sources are configured in the service rather than inherited from the .pbix. Chris Webb documented the practical consequence years ago: reports that work in Desktop with checks ignored can fail to refresh once published because the gateway still applies them (disabling data privacy checks). Set levels in the service under Manage connections and gateways, and confirm them in each gateway data source's configuration.

Configuring the gateway levels is a separate step from configuring the file. Use Manage connections and gateways, open each data source, and check the privacy level there — don't assume the .pbix carries it. Folding behavior you verified in Desktop can also differ once the refresh runs server-side; see our walkthrough on proving RangeStart/RangeEnd folding for incremental refresh if that's part of your model. And when you need to check numbers that look wrong after a refresh, the explanation of why DISTINCTCOUNT matrix totals differ from row sums is a useful next stop — it's a measure issue, not a privacy one.

Acceptance sequence: Desktop refresh with privacy on, publish, manual refresh in the service, gateway source privacy levels confirmed, then observe one scheduled run.

Is "Ignore Privacy Levels" Ever Acceptable?

Microsoft's position is direct: don't enable Fast Combine unless you are confident the data source doesn't contain sensitive or confidential data, because it could expose that data to an unauthorized person. The security best practices for Power Query go further and list avoiding the option among its data-protection guidance.

An exception is defensible only when all of the following hold: every source in the query is genuinely public or non-sensitive; the combination is documented; the setting is scoped to a single file rather than set globally; and the decision has a named owner and a recorded rationale. Get it wrong and the consequence is a disclosure event, not a performance setting — data from a private source can be folded into an external request.

There is also a practical trap that settles most arguments: the setting does not apply to semantic models, so it cannot be the basis of a production fix anyway. Frame the decision so you could defend it in an audit: what the sources contain, who approved the exception, which file it applies to, and when it will be reviewed.

Verify Your Result: A Short Acceptance Checklist

Confirm the fix is complete and durable before you close the ticket. Each item below can usually be confirmed by a refresh or a settings check:

  • The specific error string no longer appears on refresh.

  • Privacy levels are set explicitly on every source in the query, not left at default.

  • The query still folds where it should, checked with folding indicators or View Native Query.

  • Refresh duration is within an acceptable band versus the pre-fix baseline.

  • The semantic model refreshes successfully in the service.

  • Gateway data source privacy levels match the intended design.

  • Any use of Fast Combine is documented and scoped to a single file.

Where Should You Check Before You Commit to a Fix?

Product behaviour moves. Every product statement in this article was checked on 2026-11-27 against Microsoft Learn: the Data Privacy Firewall, privacy levels, Table.Buffer, and the Desktop setting page. Preview labels, defaults, and portal paths change, so re-check them against the build you actually run. The M templates above are example configurations, not a substitute for testing in your own environment.


FAQ

Does the privacy firewall relaxation mean the first error variant is gone?

No. On builds where the setting applies, it permits a partition to reference another partition and access a data source only when the involved privacy levels are compatible, and it doesn't disable the firewall. Older builds, and products that haven't adopted the behavior, still block the pattern.

Can I call Value.Firewall manually?

No. It is an internal function the engine injects when it rewrites cross-partition references. Microsoft documents it as part of how partitioning works, not as an authoring tool you invoke yourself.

Are Power Platform dataflows affected by privacy levels?

They aren't subject to them right now. Microsoft's Data Privacy Firewall page says "privacy levels are currently unavailable in Power Platform dataflows," so level-based conflicts don't arise there the same way.

Can Formula.Firewall appear on a report that refreshed fine for months?

Yes. Changes in query evaluation or source metadata can redraw partition boundaries, which is why a report that refreshed for months can start failing without an edit.

Do Table.Buffer and Fast Combine behave the same way?

No, and neither is a universal fix. Table.Buffer isolates a table in memory and may slow a query by blocking downstream folding; Fast Combine ignores privacy levels but doesn't apply to semantic models. Neither reconciles incompatible levels on its own.

Related Articles