Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Syntax for a boolean function

I want to create a VBS function that returns true or false if a date is between StartDate and EndDate. (Just to keep the formulas more compact and readable)

I wrote:

FUNCTION twixt(Target,StartDate,EndDate)

IF Target > StartDate AND Target < EndDate THEN

twixt = TRUE

ELSE

twixt = FALSE

END IF

END FUNCTION

However, this doesn't seem to return either TRUE or FALSE, and when I use it other formulas, such as

IF(twixt(BCD,StDate,EDate),sum(Sales),0)

I just get NULLs as a result.

As usual, there is nothing in the documentation about the method of creating functions. Do I need to declare the function as LOGICAL, BOOLEAN, etc.?

What should I expect as a return value? TRUE/FALSE, or -1/0?

Thanks for any help.

4 Replies
fosuzuki
Partner - Specialist III
Partner - Specialist III

Have you tried using dollar-sign expansion with parameters?

Check the attached qvw.

The idea is to use a variable

fTwixt = if($1>$2 and $1<$3, 1, 0)

and the expression will be:

=$(fTwixt(Target, StartDate, EndDate))

Hope this helps

Fernando

Not applicable
Author

Hi Kevin,

in QlikView you can define Procedures by the keyword SUB

but there are no user defined functions like you tried. They are on the wishlist for some time.

Simple functions can be done with variables as Fernando showed above.

Ciao

Klaus

sebastiandperei
Specialist
Specialist

Hi Kevin

When you assign True value to a variable on VBScript, this var will get the '-1' value. If you assign False, the value is '0'.

Try with this:

IF(twixt(BCD,StDate,EDate)=-1,sum(Sales),0)

Not applicable
Author

Sorry Kevin,

you were talking about VBS Fernando and me we were in a QV script.

Ciao

Klaus