Dynamically allows user to filter range or multiple values

SBM

New Member
Joined
Feb 25, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I created a parameter table to enable the final user to pre-filter data based on their input. When I try a single input (e.g. month number) it works well --> I created a function as explained by Ken Puls (Building a Parameter Table for Power Query)

What I try to do is to allow the final user(s) to select/filter based on:
  • a single value (is working perfectly);
  • a range (e.g month 2 till 6);
  • multiple values (e.g months 2,4,6 and 8)
The parameter table is represented as follows in excel:

ParameterTable.png

I tried to define them as a list {2,4,6} and {2..6} but I'm not sure how to use it afterwards for filtering my query.
With the getParameter function I have the correct input {2,4,6} , but don't know how to use it for filtering.
I tried to use List.Contains but of course my column containing the months is not a list so this generates an error.
Any idea how to easily solve this?

To summarize: I would like to replace this code and make it dynamic based on my parameter table in Excel
Multiple values:
Power Query:
Table.SelectRows(#"Inserted Month", each ([Month] = 2 or [Month] = 4 or [Month] = 6))
Range:
Power Query:
Table.SelectRows(#"Inserted Month", each [Month] >= 2 and [Month] <= 6)

Thanks for your suggestions.

Have a nice day!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

Maybe this can help you fine tuning your approach.
I would not use List syntax in Excel. So here I use the month references with a space in between.
Book1
CD
2ParamValue
3MonthRange3 6
Sheet1


Not using any function here, but basically I use the input table and convert the parameter MonthRange to a list. This Query is called MonthRange too.
Power Query:
let
    Source = ParamTbl,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Param] = "MonthRange")),
    Value = #"Filtered Rows"{0}[Value],
    #"Split Text" = Text.Split(Value, " "),
    Custom1 = List.Transform(#"Split Text", each Number.From(_))
in
    Custom1

Applying this parameter in the filter function:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each [Month] >= List.First(MonthRange) and [Month] <= List.Last(MonthRange))
in
    #"Filtered Rows"

I hope this helps you on the way.
 
Upvote 0
For multiple months it could be like this.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each (not List.IsEmpty(List.Intersect({{[Month]},MultipleMonths}))))
in
    #"Filtered Rows"

Actually looking forward to some PQ wizards answering with more optimal M.
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top