# New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
QlikWorld May 10-12, Online and Free! REGISTER NOW
cancel
Showing results for
Did you mean:
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)

• ### Set Analisys

1 Solution

Accepted Solutions
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.
7 Replies
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.
MVP

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

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

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

Partner

Hi @Gopinath213 ,

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

Contributor II
Author

Dear Claudiu,

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

Regards,

Gopinath

Contributor II
Author

Thank you premvihari !

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