A dynamic filter in Power Query is a filter whose value is not typed into the query itself but comes from somewhere else — a cell in a table, a named parameter, or an argument passed to a custom function. The shortest working version is: load the values you want to filter by into a table, turn that table into a query, right-click the cell value and choose Drill Down so the query returns a single value, then use Manage Parameters or a function argument to feed that value into your filter step. The query then re-filters whenever the source value changes, instead of you editing the step by hand.
That matters most in refreshable reports. A hard-coded filter breaks silently when the person who built the file leaves, or when the date rolls over. A dynamic filter keeps working because the logic lives in the query, not in a number you typed once.
What You'll Need
- Power BI Desktop, or Excel with Power Query (the Data tab, then Get & Transform Data). Menu labels can differ slightly by version and by product — Power BI and Excel share the Power Query engine but not every button sits in the same place.
- A source table or file you can connect to. The examples below use a single table, but the same pattern works on CSV files, databases and SharePoint lists.
- Basic familiarity with the Applied Steps pane on the right of the Power Query Editor, and with the formula bar. Everything you click writes M code; you will edit a little of it.
- If you plan to publish, a workspace where you can refresh a semantic model or workbook — a filter built on a local file path will fail once refresh moves to a service.
Step-by-Step
- Load your data without filtering yet. In Power Query Editor, confirm the column you want to filter on (for example Region or OrderDate) has the correct data type. Click the type icon in the column header and set it to Text, Date or Whole Number as appropriate. A filter on a column stored as text where you expect dates is the single most common reason dynamic filters return nothing.
- Create a control query for the value. Go to Home > Enter Data and type your allowed values into a small table — one column, one row per value, with a clean header such as Region. Name it something obvious in the Queries pane, for example RegionFilter. If you are driving the filter from a cell in a worksheet instead, select that cell and use Data > From Table/Range; make sure the cell sits in its own properly named table, not loose on the sheet.
- Turn that query into a single value. Right-click the value cell in the RegionFilter query and choose Drill Down. The query now returns a scalar, and the formula bar shows something like
= "North". Rename the query to SelectedRegion so its purpose is clear in the steps that follow. - Add the filter step to your main query. Go back to the data query. Click the filter arrow on the Region column, choose Text Filters > Equals, pick any value to create the step, then click OK. You are not keeping this value — you are generating the step that you will now rewrite.
- Replace the literal in the formula bar. With the new Filtered Rows step selected, look at the formula bar. It will read roughly
= Table.SelectRows(PreviousStep, each [Region] = "North"). Delete the quoted"North"and type the name of your control query instead, so it readseach [Region] = SelectedRegion. Press Enter. The preview updates immediately, and the step now points at the query rather than a fixed string. - Test it by changing the control value. Open SelectedRegion, change North to another region, then go back to the main query and click Refresh Preview on the Home tab. If the row count changes, the wiring works. If it throws an error, see the troubleshooting section — usually it is a type mismatch or a duplicated column name.
- For multiple values, switch to a list and use
List.Contains. If the control query holds several rows, drill down on the column header instead of a single cell to get a list, then rewrite the filter aseach List.Contains(SelectedRegions, [Region]). This is the pattern to use when the user should be able to pick two or three regions rather than one. - For reusable logic, convert to a function. Right-click the main query in the Queries pane and choose Create Function. Accept the parameter it offers (or edit the M so the filter value is an explicit parameter). You can now invoke the function once per value in another query — for instance by adding a custom column that calls it. This is how a single query becomes a template for many filtered extracts.
- Handle the empty-selection case. A drill-down on an empty table errors out. Guard against it by wrapping the filter so that an empty or null control value returns all rows:
each SelectedRegion = null or [Region] = SelectedRegion. Decide deliberately whether "nothing selected" should mean "everything" or "nothing", because the two behave very differently for a report consumer. - Load and verify. Click Close & Load (or Home > Close & Load). Change the control value and refresh the destination table to confirm the filter follows. In Power BI, use Refresh on the ribbon; in Excel, right-click the result table and choose Refresh.
Common Mistakes
- Leaving the literal in place. The step still says
"North"because the formula was edited but not committed — press Enter and check the step name changed to reflect the new reference. - Drilling down on the wrong query. If you drill into the main table's column rather than the control query, you get a single hard value, not a live reference. The control query must be separate and named.
- Filtering before the type is set. A date column read as text will never match a date parameter. Set types before filtering.
- Case and whitespace mismatches.
"north","North "and"North"are all different. Trim and standardise in the control query, not in the filter step. - Forgetting the refresh path. A control table that lives in a local workbook will break when the report is published and refreshed elsewhere. Keep the control values somewhere the refresh can reach.
- Using a filter where a slicer belongs. A Power Query filter physically removes rows before the model loads. If users need to toggle values themselves in a report, they want a slicer on the model, not a query-level filter.
Tips
- Name every step. Click a step and press F2, or right-click and rename. A step called Filtered Rows tells you nothing six months later.
- Keep the control query loaded as a connection only, so it does not clutter the data model.
- Write filter steps as one condition per step while debugging, then combine them once you know each works.
- For dates, a relative control (such as a start date parameter) plus
[OrderDate] >= StartDateadapts better than a fixed range. - Remember that Power Query filters are applied per query and are invisible to report users — document them where the report owner will see them.
Troubleshooting
If the filter returns an error rather than an empty table, click the erroring step and read the message in the formula bar's yellow band. Expression.Error: We cannot apply operator = to types Text and Number means the two sides disagree on type — fix the column type or convert the control value. We cannot convert the value null to type Text usually means the drill-down hit an empty cell.
If the table loads but is empty, compare the control value with the actual column values character by character: watch for trailing spaces, inconsistent capitalisation and values stored with leading zeros. Temporary steps that Trim and Uppercase the column before the filter are often worth keeping permanently.
If nothing changes when you edit the control query, you are probably looking at a cached preview. Click Refresh Preview. If the published report does not update, check that the query refreshes on the schedule you expect and that the control source is reachable from the refresh machine.
If the whole query fails after you convert it to a function, delete the function and rebuild from the original query rather than patching the generated M by hand — the auto-generated invocation steps are easy to break.
Frequently Asked Questions
Can a Power Query filter read a value from a cell the user types into?
Yes, provided that cell is inside a properly defined table and the query drills down to it. A cell outside any table cannot be referenced reliably.
What is the difference between a parameter and a control query?
Manage Parameters creates a named value you edit in a dialog. A control query reads values from data. Both can feed the same filter step; parameters are simpler, control queries are easier to hand to other people.
Can I filter on several values at once?
Yes — use List.Contains against a list rather than = against a single value.
Does a dynamic filter replace a slicer?
No. A query filter removes rows before loading; a slicer filters what is already loaded. Use the query filter for data you never want in the model, and a slicer for choices users make interactively.
Why does my filter work in Desktop but fail after publishing?
Almost always a source path or credential problem. A local file or personal drive is not reachable from the refresh environment.