Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
NormanStanleyBadger

Variables - Optional Parameters

Hi,

Is it possible to have optional parameters in an expression stored in a variable?

vSKUcount = 

Count(

{<

[Year]={$1}, 

[Type]={$2}   <<< ?Optional?

>}

Distinct [SKU ID])

$(vSKUcount(2022,?Optional?))

 

Many thanks,

NSB

Labels (3)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You can't have optional parameters in the typical meaning, but you can pass an empty string for a skipped parameter and test the length. Like this:

vSKUcount = 
Count(
{<
[Year]={$1}
$(=if(len($2),',[Type]={$2}', ''))
>}
Distinct [SKU ID]);

$(vSKUcount(2022,''))

or

$(vSKUcount(2022,mytype)) 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

3 Replies
NormanStanleyBadger
Author

I may have a solution for this, I have have used the wildcard character * for any parameters that I would like to be optional, hopefully returning all possible selections which effectively does what I need.

If any body knows any potential issues with this or a more elegant solution, please do let me know.

Many thanks

NSB

vSKUcount =

Count(

{<

[Year]={$1}, 

[Type]={$2}   <<< Optional?

>}

Distinct [SKU ID])

$(vSKUcount(2022,*))

 

 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You can't have optional parameters in the typical meaning, but you can pass an empty string for a skipped parameter and test the length. Like this:

vSKUcount = 
Count(
{<
[Year]={$1}
$(=if(len($2),',[Type]={$2}', ''))
>}
Distinct [SKU ID]);

$(vSKUcount(2022,''))

or

$(vSKUcount(2022,mytype)) 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

NormanStanleyBadger
Author

Nice one. Thank you. 👍