Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

subfield function with getselectedcount

Hi all,

Where the variables have the following values:

vItemOpts = 'fieldname1;fieldname2;fieldname3'

vCurrOpt = 2

This expression in a text object returns the string 'fieldname2'

=SubField(vItemOpts, ';', vCurrOpt)

and where the field 'fieldname2' is used in a list box and has 1 value selected, this returns the value 1

=GetSelectedCount(fieldname2)

but this combination of the two returns null:

=GetSelectedCount(SubField(vItemOpts, ';', vCurrOpt))

Is this because GetSelectedCount sees the string 'SubField....' as a fieldname? How can I get around this?

Regards,

Gordon

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think John's on the right track. You just need to add some indirection using another variable.

SET vItemOpts = 'fieldname1;fieldname2;fieldname3';
SET vCurrOpt = 2;
SET vField = "=SubField(vItemOpts, ';', vCurrOpt)";

and then use the expression:

=GetSelectedCount($(vField))

-Rob

View solution in original post

3 Replies
johnw
Champion III
Champion III

Subfield() returns a string, so your expression probably gets evaluated like this:

=GetSelectedCount(SubField(vItemOpts, ';', vCurrOpt))
=GetSelectedCount('fieldname2')
=null (because you can't get selections for a string, only for a field, and it doesn't recognize it as a field)

I'm not thinking of how to tell it that you mean a field name instead of a string, assuming I even have the problem correct. There's got to be a way, though. Maybe something with dollar sign expansions, variables, or who knows what.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think John's on the right track. You just need to add some indirection using another variable.

SET vItemOpts = 'fieldname1;fieldname2;fieldname3';
SET vCurrOpt = 2;
SET vField = "=SubField(vItemOpts, ';', vCurrOpt)";

and then use the expression:

=GetSelectedCount($(vField))

-Rob

Not applicable
Author

Thanks Rob, John - that cracked it!

Regards,

Gordon