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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
ianwilson
Contributor III
Contributor III

Hide object based on current selection in a specific field

Hi,

I'm trying to hide a sheet object unless a single selection is made in a specific field.

If I have 3 fields: FieldA, FieldB and FieldC, I want to display an object if FieldB only has a single selection and hide the object if FieldB has 0 or 2+ selections. It does not matter what is selected in FieldB, only the quantity.

I am falling at the first hurdle which I think is to extract the selection for the field from the GetCurrentSelection() function. I came up with the following:

=TextBetween(GetCurrentSelections(),'FieldB: ',chr(13),)

This works providing FieldB is not the last selection, because the selections in the GetCurrentSelection are separated by a CR. But if FieldB is the last selection there is no CR at the end of the string.

If someone knows an easy way to do this I would be really pleased, otherwise I need to extract the field selection from the GetCurrentSelection() result in the following circumstances:

No FieldB selection

FieldA: 1,2,3

FieldC: A,B,C

Only FieldB selection:

FieldB: first, second, third

FieldB is the first selection:

FieldB: first, second, third

FieldC: A,B,C

FieldB is the last selection:

FieldA: 1,2,3

FieldC: A,B,C

I'm hoping there is an easy way to do this without a complicated nested if statement.

Thanks in advance.

1 Solution

Accepted Solutions
sunny_talwar

How about this

=GetSelectedCount(FieldB) = 1

View solution in original post

3 Replies
ianwilson
Contributor III
Contributor III
Author

I got this working with the following statement: If there is only 1 item selected in FieldB this returns the value of the selection in FieldB, otherwise it returns a 0. Surely there is a better, more elegant, faster performing way than this?

=If(if(substringcount(GetCurrentSelections(),'FieldB: ')=1,if(findoneof(TextBetween(GetCurrentSelections(),'FieldB: ',''),chr(13),)=0,TextBetween(GetCurrentSelections(),'FieldB: ',,),TextBetween(GetCurrentSelections(),'FieldB: ',chr(13),),),0)=0,0,If(if(substringcount(GetCurrentSelections(),'FieldB: ')=1,if(findoneof(TextBetween(GetCurrentSelections(),'FieldB: ',''),chr(13),)=0,TextBetween(GetCurrentSelections(),'FieldB: ',,),TextBetween(GetCurrentSelections(),'FieldB: ',chr(13),),),0)='-',0,if(findoneof(if(substringcount(GetCurrentSelections(),'FieldB: ')=1,if(findoneof(TextBetween(GetCurrentSelections(),'FieldB: ',''),chr(13),)=0,TextBetween(GetCurrentSelections(),'FieldB: ',,),TextBetween(GetCurrentSelections(),'FieldB: ',chr(13),),),0),chr(44),)>=1,0,if(substringcount(GetCurrentSelections(),'FieldB: ')=1,if(findoneof(TextBetween(GetCurrentSelections(),'FieldB: ',''),chr(13),)=0,TextBetween(GetCurrentSelections(),'FieldB: ',,),TextBetween(GetCurrentSelections(),'FieldB: ',chr(13),),),0))))

Thanks in advance.

sunny_talwar

How about this

=GetSelectedCount(FieldB) = 1

ianwilson
Contributor III
Contributor III
Author

Spot on Sunny T - thanks.

I couldn't believe there wasn't an easy way of doing this. Guess I need to refine my search techniques!

Cheers