Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
HugoBoyle
Contributor II
Contributor II

Storing Filter pane selection values in Variable

I have a script that is loading data into a chart in Qliksense.
In my chart I have a filter pane where I am selecting Year (file name MI_YEAR) and Period (Field name MI_PERIOD).
The chart is showing the correct data.
 
What I want to do now is store my selected values for MI_YEAR and MI_PERIOD in variables.
I have created a new variable called vSelect_Year with the expression of 
= GetFieldSelections(MI_YEAR,'","') 
When I try to add this variable to my chart it is showing as NULL.
If the selection is MI_YEAR = 2023 and MI_PERIOD = 05 I want these values stored into my varaibles so that I use them in calculations in my chart (i.e. to determine the previous year/period 2023 / 04). 

Labels (3)
1 Solution

Accepted Solutions
marcus_sommer

You couldn't store a previous selection within a variable because it's evaluated by each selection. Beside this you may struggle with the syntax by creating and calling the variables which needs to be always done in the context which kind of data are stored and where they are used.

However you don't need variables for this kind of task else you could apply this as set analysis conditions within the expressions, for example with:

sum({< Period = {"$(=max(Period))"}>} Value) 

returning the results for the selected Period respectively to the max. possible Period if none is selected. With:

sum({< Period = {"$(=max(Period)-1)"}>} Value) 

you will get the the results from the previous Period.

The field Period must not be shown in the UI else selecting per Year and Month will work for it - if this field is related to them within the calendar and there created per: Year * 12 + Month. That's not mandatory necessary but it simplifies the matter to use a single field for it which will also work over the years.

View solution in original post

3 Replies
Channa
Specialist III
Specialist III

=Concat(DISTINCTMI_YEAR,',')

Channa
HugoBoyle
Contributor II
Contributor II
Author

I think you might have misunderstood what I am trying to do.

I am trying to save the value from my filter pane into a variable. Concat is a string function for joining strings.

Or am I missing something with CONCAT ??

marcus_sommer

You couldn't store a previous selection within a variable because it's evaluated by each selection. Beside this you may struggle with the syntax by creating and calling the variables which needs to be always done in the context which kind of data are stored and where they are used.

However you don't need variables for this kind of task else you could apply this as set analysis conditions within the expressions, for example with:

sum({< Period = {"$(=max(Period))"}>} Value) 

returning the results for the selected Period respectively to the max. possible Period if none is selected. With:

sum({< Period = {"$(=max(Period)-1)"}>} Value) 

you will get the the results from the previous Period.

The field Period must not be shown in the UI else selecting per Year and Month will work for it - if this field is related to them within the calendar and there created per: Year * 12 + Month. That's not mandatory necessary but it simplifies the matter to use a single field for it which will also work over the years.