Jul 11 2020 03:56 PM
Jul 12 2020 04:10 AM
Hi @user_2020
can you please recreate the sample and attached the Excel file
Manually feed you comments in workbook to understand your query & provide you the best solution
Regards, Faraz Shaikh | MCT, MIE, MOS Master, Excel Expert
If you find the above solution resolved your query don't forget mark as Official Answer to help the other members find it more
Jul 12 2020 07:29 AM
To demonstrate how to use a parameter in the way you described, I created two queries against two separate lists of countries from Wikipedia:
1. List of countries and dependencies by population
After filtering away the duplicated column headers, I have this:
2. List of countries and dependencies by population density
Similarly:
I have also created a parameter using Home>Parameters>Manage Parameters>New Parameter:
In my example, I want to filter both lists by the same country.
I've configured the New Parameter like this:
Now, I can filter each query on the column that contains the country name.
From the filter drop-down in the PowerQuery Editor, I select Text Filters>Equals, then I configure the Filter Rows dialog to be equal to the value of my parameter:
Note that I have changed the second box on the first row to Parameter and the SelectedCountry parameter was selected automatically. If you have more than one parameter, you may need to select this yourself.
I repeat this step for each query containing a country column, then Close&Load back to the workbook.
Now, when I want to change the parameter, I simply change the value of the parameter once and use Refresh All to re-filter all the queries by the new country.
It should be simple to imagine and implement how this will work for multiple parameter-filters.
Jul 12 2020 10:57 AM
Thanks, This is a great Idea. I am trying to create a list of Inventory Number as a parameter. However, it seems I could only choose one inventory number at a time. Does that mean I need to create a parameter for each Inventory Number? Or if there is a way to create a list of Inventory Number at once?
Jul 12 2020 11:57 AM
SolutionOne approach to using a list of values as a filter is to create a filter table and use Merge with an inner join to filter the queries.
I created a filter table on a separate sheet in my workbook and put two countries in there:
Now I select the PopulationStatistics query and use Home>Merge Queries and configure it like this:
Because I'm using an inner join, this has the effect of removing rows from the PopulationStatistics table that don't exist in the CountryFilter query.
This will add a column to the right of the PopulationStatistics query called CountryFilter, but we don't need that, so just right-click it and select Remove.
I then repeat the whole merge process for the LandUse query (or whatever other query has country in it), then use Home>Close&Load.
When the Close&Load has finished, you can delete the additional sheet created for the filter query so that you just have one sheet for each of your original queries and one sheet for your filter table and the list of queries will show "Connection only" against the filter:
Now, when you change the rows in the filter table (add/remove/edit), you can refresh all queries to re-filter them.
Jul 12 2020 12:10 PM
Working with Excel I'd suggest to keep parameters in Excel Table or named range(s). Query it, parse on separate parameters and combine them with SQL query string. Implementation is slightly different depends on your privacy setting is Ignore or not.
From end user point of view that is more suitable way to change parameters.
Jul 12 2020 03:13 PM
Thanks a lot. This works like a charm.
On a separate note, I am little surprised that we cannot create a list as a filter in power query. I thought it'd be easy if we could create a parameter equivalent to SQL like Inventory_number in ('aaaaa','bbbb','cccc')
Jul 13 2020 12:27 AM
I see nothing complex here as well. If we have such source and table with filter
that is one step to apply the filter and receive the result. Entire script is
let
GetFilter = Excel.CurrentWorkbook(){[Name="tblFilter"]}[Content],
Source = Excel.CurrentWorkbook(){[Name="tblSource"]}[Content],
FilterTable = Table.SelectRows(Source, each List.Contains(GetFilter[A],[B]))
in
FilterTable
Jul 12 2020 11:57 AM
SolutionOne approach to using a list of values as a filter is to create a filter table and use Merge with an inner join to filter the queries.
I created a filter table on a separate sheet in my workbook and put two countries in there:
Now I select the PopulationStatistics query and use Home>Merge Queries and configure it like this:
Because I'm using an inner join, this has the effect of removing rows from the PopulationStatistics table that don't exist in the CountryFilter query.
This will add a column to the right of the PopulationStatistics query called CountryFilter, but we don't need that, so just right-click it and select Remove.
I then repeat the whole merge process for the LandUse query (or whatever other query has country in it), then use Home>Close&Load.
When the Close&Load has finished, you can delete the additional sheet created for the filter query so that you just have one sheet for each of your original queries and one sheet for your filter table and the list of queries will show "Connection only" against the filter:
Now, when you change the rows in the filter table (add/remove/edit), you can refresh all queries to re-filter them.