Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

To get data for two years by selecting year using line chart

Hi all,

I have two years of data(2016,2017) in my QVD. I need to show my data in line chart.If I select 2017 year my data is showing in line chart but if I select 2016 it is not showing.I used expression like sum(Field name) and I browsed but I can get like

sum({$<year={"$(=only(year))"}>}Field-name) //current year

sum({$<year={"$(=only(year)-1)"}>}Field-name)

but it doesn't work.Is there any other expression to get it.Please help me to get it as soon as possible.

Thanks in Advance!!!!

Regards,

Harini S

1 Solution

Accepted Solutions
german24
Partner - Contributor III
Partner - Contributor III

Hi,

try this...

It show 2017 for the selecction Year = 2017:

sum({$<year={"$(=Max(year))"}>}Field-name) //current year

It show 2016 for the selecction Year = 2017:

sum({$<year={"$(=(Max(year)-1))"}>}Field-name)


Best regards,

German.

View solution in original post

8 Replies
sunny_talwar

which of the three expressions are you using in your chart?

adamdavi3s
Master
Master

sum(Field name) will work if you have year as a dimension

sum({$<year={"$(=only(year))"}>}Field-name) will work for the year you have selected (and only when you have one selected)

sum({$<year={"$(=only(year)-1)"}>}Field-name)will work when you have 2017 selected, but not when you have 2016 selected as you don't have year 2015 available


What exactly do you want to show?

A line comparing both years? If so add year as a dimension and use the first formula

Not applicable
Author

Thanks for your response!!!!

currently i am using sum(Field-name) but I tried those three expression but it doesn't work.

Not applicable
Author

Thanks for your response and great Explanation.

I don't want to add any value of 2016  and 2017.I need to just show when I select 2016 that year data to display in line chart and by selecting 2017 that year data to display in line chart.

I have tried those three expression but it doesn't work.Do u have any idea....

german24
Partner - Contributor III
Partner - Contributor III

Hi,

try this...

It show 2017 for the selecction Year = 2017:

sum({$<year={"$(=Max(year))"}>}Field-name) //current year

It show 2016 for the selecction Year = 2017:

sum({$<year={"$(=(Max(year)-1))"}>}Field-name)


Best regards,

German.

sunny_talwar

Is your calendar table (or year field) correctly connected to the fact table which holds Field-name? Can you share an image of your data model?

adamdavi3s
Master
Master

I agree with Sunny, I don't think your data is correctly linked otherwise sum(Field name)  would always show you the correct data based on your selections

Not applicable
Author

Yes guys,I have add restriction so only it didn't work.Now I fixed it .Thanks for your help and quick reply.sorry for inconvenience.