Forum

Optional Parameter ...
 
Notifications
Clear all

Optional Parameter from Excel Table

5 Posts
3 Users
0 Reactions
125 Views
(@muralidaran)
Posts: 2
New Member
Topic starter
 

Hi,

I have a query which pulls data from an access database stored on the network to an excel file using power query, I have added parameters from excel table and it works fine when all the parameter values are passed, what I couldn't solve is that these parameters should be optional, when there is a null value in any of the parameters 2 & 3 then it should return all the records. Appreciate your help to fix this code, thanks.

Parameters-1 = FilePath

Parameters-2 = String 'P4'

Parameters-3 = String 'A123456'

let
Source = Access.Database(File.Contents(fParameters("Parameters",1)), [CreateNavigationProperties=true]),
_TSData = Source{[Schema="",Item="TSData"]}[Data],

#"Filtered Bay & Emp" = Table.SelectRows(_TSData, each ([Bay No] = fParameters("Parameters",2)) and ([Emp No] = fParameters("Parameters",3)))
in
#"Filtered Bay & Emp"

 
Posted : 22/08/2023 2:58 am
Riny van Eekelen
(@riny)
Posts: 1196
Member Moderator
 

Try by using two separate Filter steps, each testing if the parameter equals null or not. Something like this:

Filter1 = if fParameters("Parameters",2) = null then _TSData else Table.SelectRows(_TSData, each ([Bay No] = fParameters("Parameters",2)),
Filter2 = if fParameters("Parameters",3) = null then Filter1 else Table.SelectRows(Filter1, each ([Emp No] = fParameters("Parameters",3))

 
Posted : 23/08/2023 2:44 am
(@muralidaran)
Posts: 2
New Member
Topic starter
 

Thanks, that helps.

After adding a close bracket for Filter1 & 2 it works.

Filter1 = if fParameters("Parameters",2) = null then _TSData else Table.SelectRows(_TSData, each ([Bay No] = fParameters("Parameters",2))),
Filter2 = if fParameters("Parameters",3) = null then Filter1 else Table.SelectRows(Filter1, each ([Emp No] = fParameters("Parameters",3)))

 
Posted : 23/08/2023 5:04 am
Riny van Eekelen
(@riny)
Posts: 1196
Member Moderator
 

Great! Well spotted. I couldn't test the code myself and forgot to add the extra parentheses.

 
Posted : 23/08/2023 6:07 am
Alan Sidman
(@alansidman)
Posts: 223
Member Moderator
Share: