Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

is it possible to nest udfs or use recursion

Hi,

1. Is it possible to nest one udf into another (I wasn't able to do it)? If yes, how?

2. Is it possible to use recursion (this is just a variant of the first question)? If yes, how? -> when I tried it QV expanded the function until it had space and then raised an error: too many iterations or something similar.

Regards

Andrzej

7 Replies
marcus_sommer

Please elaborate more practically what you are trying to do and why.

- Marcus

Anonymous
Not applicable
Author

hi,

e.g. @recursion: split a string: 'xx xxxxxxxxx xxxx xxxxxxxxxxx xxxxx xxxxxx xxx x x xxxx xxxx' into pieces of 10 characters but so that the split is being done only on spaces

this is just a dummy code to show the concept:

set udf_split= if(len(left($1,index($1,'  ' ,1))<=$2 or len($1)<=$2 or substrincount($1, '  ')=0,

                          trim($1),

                         $(udf_split(left($1,index($1,'  ' ,1),$2))

                              );

FOO:

load

     $(udf_split(dimension)) as MyDim

resident MyTable;

@nesting:

BOO:

load

     $(udf_Outer($(udf_Inner(1,x)))) as Something

resident MyTable;

marcus_sommer

This could be done with something like:

load recno() as ID, iterno() as SubID, subfield(String, ' ' , iterno()) as SubString

From Source

while iterno() <= substringcount(String, ' ') + 1;

- Marcus

Anonymous
Not applicable
Author

i know it's a bed practice to answer one's comment but i cannot seem to find the edit:

in the udf_split in the 'false' part there should be something storing the left(...) part but that is irrelevant, I'm just interested in the ability to use recursion, the answer can be presented on n!

the output should be something like:

  

xx xxxxxxxxx
123456789101112
xxxx xxxxxxxxxxx
12345678910111213141516
xxxxx xxxxxx
123456789101112
xxx x x xxxx
123456789101112
xxxx
1234
marcus_sommer

Sorry, I don't understand what do you want to do. Please give an example in a tabular form like:

source:

Load * inline [

String, OtherFields

.......

],

Output:

F1 ... Fn

values ......

- Marcus

Anonymous
Not applicable
Author

1. I really appreciate you're trying to find a workaround but the point is: whether is it possible to use recursion in udfs or nested functions in QV.

2. please imagine:

single dimension, single expression bar chart:

     - dimension name: Animals

     - expression: count(Animals)

Animals:

1. Cat

2. White Cat

3. Very Fluffy White Cat with a Dark spot on the Tail

4. Not So Fluffy Cat

5. Not So Fluffy Cat but also Nice

I have limited space so i would like to use $(udf_split(Animals,9)) instead of Animals and have:

1. Cat

2. White Cat

3.  Very Fluffy

     White Cat

     with a Dark

     spot on the

     Tail

4.  Not So Fluffy

     Cat

5.  Not So Fluffy

     Cat but also

     Nice

regards

Andrzej

marcus_sommer

Take a look on this: Re: Loop for Field name.

- Marcus