Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
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
Partner
Partner

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

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.

8 Replies

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

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

adamdavi3s
Honored Contributor

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

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

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

Thanks for your response!!!!

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

Not applicable

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

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....

Partner
Partner

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

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.

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

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
Honored Contributor

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

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

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

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.