Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
eva_maria
Contributor III
Contributor III

previous and actual selected year values

In my attached file, i've a chart (Points) where I show values corresponding to the previous year to the selected one.

I also need to show (on the same chart) the selected year values for Comm and value fields.

I appreciate any help!

1 Solution

Accepted Solutions
Sergey_Shuklin
Specialist
Specialist

Hello!

Please, find a green table in the attachement. Is this the result you've wanted to achieve?

View solution in original post

11 Replies
Sergey_Shuklin
Specialist
Specialist

Hello!

Please, find a green table in the attachement. Is this the result you've wanted to achieve?

tresesco
MVP
MVP

Not sure if understood right. To see, data for current selection (year) and last to current selection year, you may try using exp, like:

Sum({$+<Year={$(=(Year)-1)}>}Value)

eva_maria
Contributor III
Contributor III
Author

Sergey, your reply is perfect. Please, could you explain me how does it work the expresions  with pick, match, and

ValueList?

What's the different between $(=(Year)-0) and $(=(Year))?

Thanks for your invaluable help!!

Regards

eva_maria
Contributor III
Contributor III
Author

Hi Tresesco. Thanks for be willing to help and try to solve my question.

I've seen your file and it really does not fit my question (may be my own fault) but your expresision also show the selected year and i only have to show previous selected year with selected year values in another column.

Regards!!

Sergey_Shuklin
Specialist
Specialist

Glad to help 😃

ValueList() creates a field with some values, it's often used for creating a dimensions.

If we have numeric values like ValueList(1,2,3) then we can use Pick() for setting an expression values for it:

=pick(

    valuelist(1,2,3)

    ,sum(sales)

    ,count(orders)

    ,count(customers)

)

But, if we have a string values such as ValueList('jan', 'feb', 'mar') than we can't use Pick() function directly, we should use Match() function for support:

pick(

    match(

          valuelist('jan', 'feb', 'mar')

          ,'jan'

          ,'feb'

          ,'mar'

    ) //will return 1,2,3 respectively

  ,sum({<mon={'jan'}>}sales)

  ,sum({<mon={'feb'}>}sales)

  ,sum({<mon={'mar'}>}sales)

)

In your case I've created one valued field with ValueList(Year) and when a user selecting some year the value of ValueList(Year) is changing.

Then all I've to do is set different expressions for different calculations (Y-0 and Y-1, Point and Values).

And there no difference between Y - 0 and Y, it's the matter of taste 😃

Hope I didn't explane it confusedly.

eva_maria
Contributor III
Contributor III
Author

Sergey, Thanks for sharing your knowledge. I'lll try to assimilate your explanation.

Regards!!

eva_maria
Contributor III
Contributor III
Author

HI Sergey! one more question

Changing the year on the imput box on my real application, the following message appears

"Error in expression: All parameters to ValueList must be constant"

On my application i have three tables linked by year field

Do you know any reason??

Regards.

Sergey_Shuklin
Specialist
Specialist

Hello, Eva!

If you wish to use an inputbox you should replace 'Year' field in ValueList(Year) with your variable. And this replacement should be done in both dimension and expressions. Please, find the attached example.

eva_maria
Contributor III
Contributor III
Author

Sorry I have not expressed myself correctly. I wanted to say list box.

The funny thing is that sometimes it fails and sometimes it does not

thanks for your patience!!