Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
NormanStanleyBadger
Creator
Creator

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
MVP
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
Creator
Creator
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
MVP
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
Creator
Creator
Author

Nice one. Thank you. 👍