Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Gopinath213
Contributor II
Contributor II

Selection Year vs Previous Year comparison in Bar chart

Dear Experts, 

Im a week into my Qilk sense Learning and I'm writing this seeking your help to figure out a solution to the below scenario. 

I have a Year field ( 2016,2017,2018 & 2019) and i need to compare sales based on my current year (based on filter selection) to its previous year in a bar chart. 

 

I have tried using this below set expression in Measure 

=sum({<Year ={">= $(=max(Year)-1)<=$(=max(year))"}>}Sales)

I can see 2019 and 2018 comparison but when i'm selecting another year for example 2018 its not working and data of all years is being displayed over bar chart.  Can you please correct me 

Regards,

Gopinath  

Labels (2)
1 Solution

Accepted Solutions
Claudiu_Anghelescu
Specialist
Specialist

=sum({<Year ={">= $(=max(v_selectedYear)-1)<=$(=max(v_selectedYear))"}>}Sales)

 

create a variable v_SelectedYear = max(GetSelectionField(Year))

To help community find solutions, please don't forget to mark as correct.

View solution in original post

7 Replies
Claudiu_Anghelescu
Specialist
Specialist

=sum({<Year ={">= $(=max(v_selectedYear)-1)<=$(=max(v_selectedYear))"}>}Sales)

 

create a variable v_SelectedYear = max(GetSelectionField(Year))

To help community find solutions, please don't forget to mark as correct.
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You don't need greater than /  less than.  You only want a single year which is:

Sum({$<Year={$(=max(Year)-1)}>}  Sales)

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com

Gopinath213
Contributor II
Contributor II
Author

Dear Rob, thanks for writing !

This expression gives only the data of one year in the bar chart (2018 in this case), However my requirement is to view both the bars for 2019 and 2018 (If selection year is 2019)  and 2018 and 2017 (If the selection year is 2018)

Thank you

Gopinath

premvihari
Partner - Creator
Partner - Creator

Hi @Gopinath213 ,

Please add one more measure into bar chart for max year
Sum({$<Year={$(=max(Year)-1)}>}  Sales) -- max-1 year
Sum({$<Year={$(=max(Year))}>}  Sales)-- max year

Gopinath213
Contributor II
Contributor II
Author

Dear Claudiu,

This way it is working as expected. Thank you very much for your support !

Regards,

Gopinath 

Gopinath213
Contributor II
Contributor II
Author

Thank you premvihari !

Gopinath213
Contributor II
Contributor II
Author

On a related note,  If we want the max(year) and -1 details to be as default with out any selections, how can we achieve that ?

 

Current expressions gives result only after a particular year is selected {Using Getfieldselection

Thank you in advance - Gopinath