Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Optional Argument in Sub or Function

Using QV10 SR3.  Can you create a Function or Sub with an optional argument?  For example, can I create a Function like:

Function AddEmUp (a, b, optional c)

  AddEmUp = a + b + c

End Function

Here, the argument c is optional...so it works if I pass it two or three arguments.

2 Replies
swuehl
MVP
MVP

You can create a function variable (dollar sign expansion with arguments), e.g.

Define in the script:

Set vDateDiff = if(len($2)=0, today(), $2) - $1;

Then you can call vDateDiff with one or two arguments (second argument defaults to today()):

=$(vDateDiff('1/1/2012'))

=$(vDateDiff('1/1/2012','2/1/2012'))

IAMDV
Luminary Alumni
Luminary Alumni