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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
johnnyjohn
Creator II
Creator II

Using nested function with comma arguments

I've been stuck on this problem for a few days now, slowly driving me crazy. I've looked all throughout this forum, but haven't found an instance of this specific issue. 

My problem is pretty involved, but I've distilled it down as much as possible to the below. The example below of course isn't my use case, it's just an easily reproducible example of the core behaviour I'm trying to achieve - using nested functions and evaluating their output inside other functions. 

So I have a function, say 

Set f_Format = Pick(Match($1, 'num','text'), NUM($2), TEXT($2));

It takes 2 parameters. $1 to choose whether the value will be formatted as a NUM or as TEXT, and $2 is the value to be formatted.

I have another function. 

Set f_Calc = PICK(Match($1, 'add', 'sub'), $2 + $3, $2 - $3);

This takes 3 parameters. $1 to decide whether to add, or subtract numbers. $2 and $3 takes two values to add or subtract. 

I want to use the f_Calc function to decide what calculation to use (whether to add or subtract), return that value, then use that value in the f_Format function to format it accordingly. The issue I have is the commas in f_Calc are being used to parse f_Format, so f_Calc is never evaluated.

$(f_Format(
	'num',
	$(f_Calc('add',4,3))
))
I've tried Set vs Let, escaping characters, using REPLACE(), using $ expansions, I can't get anything to work. 
I'd appreciate any help, 
Thanks a lot
Labels (3)
10 Replies
BIAKS
Contributor III
Contributor III

Maybe you can try to do it all of it in the script like below:

Set f_Format = Pick(Match($1, 'num','text'), NUM($2), TEXT($2));
Set f_Calc = PICK(Match($1, 'add', 'sub'), $2 + $3, $2 - $3);

Transactions:
Load
	*
    ,$(f_Format('num',FirstCalc)) as Test
;
Load
	*
    ,$(f_Calc('add',Expression1,Expression2)) as FirstCalc,
;
Load
 TransLineID, 
 Round(1000*Rand()*Rand()*Rand1) as Expression1,
 Round(  10*Rand()*Rand()*Rand1) as Expression2,
;
Load 
 Rand() as Rand1,
 IterNo() as TransLineID,
 RecNo() as TransID
Autogenerate 1000
 While Rand()<=0.5 or IterNo()=1;