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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to store values of previously selected fields in a variable

Hi Qlik viewers,

I wanted to store the previously selected values of a field into a variable.

The scenario is like:

There is a list box with values A,B and C and Update button passing the selected value to the variable using getfieldselections.

When A is selected and update button is clicked. The variable will have A.

Next B is selected and update button is clicked the variable should contain A,B.

Is there a way out to retrieve previously selected value of a list box/multibox.

Thanks and regards,

Pratik

1 Solution

Accepted Solutions
vincent_ardiet
Specialist
Specialist

And if you want to let your users pick multiple values and also not do destroy the string when the clear button is pressed, change the following expressions:

First trigger on FieldA to assign vconcat:

='$(vconcat)'&if(GetSelectedCount(FieldA)>0,if(len('$(vconcat)'),',','')&concat(distinct FieldA,','))

Second trigger on FieldA to assign vconcatSA:

='$(vconcatSA)'&if(GetSelectedCount(FieldA)>0,if(len('$(vconcatSA)'),',','')&'|'&concat(distinct FieldA,'|,|')&'|')

Regards,

Vincent

View solution in original post

16 Replies
maxgro
MVP
MVP

may be (previous)

Concat({$1} DISTINCT Field, ',')

Not applicable
Author

Sorry but didnt understand..

mjm
Employee
Employee

Hello Pratik,

You can achieve this using variables from within your document, which are set under Settings > System Variables. In the document which I have attached I created a variable called vLog with the definition of

=GetFieldSelections(FieldA) & GetFieldSelections(FieldB) & GetFieldSelections(FieldC)

You can also just use this from within a text box and this keeps a log of the selections from within Fields A,B,C

If you want to look at current selections then QlikView does have a Current Selections Box.

Please look at this and if this helps resolve your question, please mark this as helpful and correct

Thanks,

Not applicable
Author

Thanks Mark for your quick response, but this isnt solving my purpose.

The requirement is: There is one field named FieldA ok. This Field has the values 1,2,3,4,5.

When 1 is selected the variable should have 1 when a button is clicked (behind the button the action to pass the field value in variable must be set, eg. getcurrentselections(FieldA)). Next when 2 is selected, and button is clicked the variable should have 1,2. Next when 3 is selected and button is clicked the variable should have 1,2,3. and so onn..

Regards,

Pratik

mjm
Employee
Employee

Hello Pratik,

Please do look at the application which I sent you. This does exactly what you require in the text box. For your assistance I have also proved this in my screenshot attachedselectionsmade.JPG

I've selected 1 A and 6 and the text box shows 1A6 to show all the selections which I have made

Please mark this as helpful and correct if you are happy this resolves your question

Not applicable
Author

But I want values to be logged for the same field Mark.

vincent_ardiet
Specialist
Specialist

Hi,

Create an empty variable for example vconcat and an action on the button to set the content of this variable with:

='$(vconcat)'&if(len('$(vconcat)') and GetSelectedCount(FieldA)=1,',','')&FieldA

Not applicable
Author

Hi Vincent,

Thanks for your reply.. But those field values I gave were just for example purpose. The actual values for the field will not be of len(Field)= 1. Im still stuck..

The scenario is: I want to eliminate values from the list box, which are once selected.

Once the user selects a value from the list box, and clicks a button. On that button I want to pass an action which will remove the selected value from the list box. That is the reason I wanted the previously selected values to be stored in a variable.

gwassenaar

Regards,

Pratik

vincent_ardiet
Specialist
Specialist

Hi,

There is not problem in my expression with len(Field)>1.

It will do what you've initially asked for: to store each selection one by one in the selected order in string.

Then, to achieve your new requirement, removing from the list box the values previously selected you can do like this:

- Create another empty variable vconcatSA

- Add a second trigger on FieldA which affect vconcatSA with the following expression:

='$(vconcatSA)'&if(len('$(vconcatSA)') and GetSelectedCount(FieldA)=1,',','')&'|'&FieldA&'|'

- Then use the following expression in your listbox instead of directly FieldA:

=aggr(only({<FieldA=>-<FieldA={<$(=replace('$(vconcatSA)','|',chr(39)))>} FieldA),FieldA)

Regards,

Vincent