Qlik Community

New to Qlik Sense

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

Announcements
Read about the latest Qlik Community enhancements on the Community News blog!
cancel
Showing results for 
Search instead for 
Did you mean: 
Staffan
Contributor II
Contributor II

Compare two years in line chart

Hello,

How do I compare the same dates in different years on a line chart? I would like to display two lines, one for 2020 and one for 2021 for comparison, not one line as in the attached screenshot.

Thanks,

/Staffan

1 Solution

Accepted Solutions
Taoufiq_Zarra

Capture.PNG

be sure you don't have any selection

dimension =DAY(Date)

measure

=Sum({<Date = {">=$(=Max(Addyears(YearStart(Date),-1))) <=$(=Max(Addyears(YearEnd(Date),-1)))"} >} Visits)

=Sum({<Date = {">=$(=Max(YearStart(Date))) <=$(=Max(Yearend(Date)))"} >} Visits)

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

21 Replies
JordyWegman
Partner
Partner

Hi Staffan,

Put this in the dimension:

Month( Date.autoCalendar.Date )

Year( Date.autoCalendar.Date )

You need two different dimensions for this.

 

Put this in the measure:

Sum( Visits )

 

Jordy

Climber

Work smarter, not harder
Taoufiq_Zarra

you can create two measure :

sum({YEAR="$(=Max(YEAR))"}>}Visits) for the year
sum({YEAR="$(=Max(YEAR)-1)"}>}Visits) for the year-1

and the month in dimension

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Staffan
Contributor II
Contributor II
Author

Thanks, 

However, this results in a single line showing 2020 to 2021. I would like to display two lines comparing day to day of april (the dataset only contains data from april 2020 and april 2021). 

My goal is something like this (but single days on x-axis instead of years):

Staffan_1-1620637910950.png

 

Staffan
Contributor II
Contributor II
Author

Thanks Taoufiq,

However, I get the following error when using the first measure:

Staffan_2-1620638091527.png

 

Taoufiq_Zarra

=Sum({<YEAR = {"$(=Max(YEAR))"} >} Visits)


=Sum({<YEAR = {"$(=Max(YEAR)-1)"} >} Visits)

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Staffan
Contributor II
Contributor II
Author

Thanks, the function works now, but I get the same type of chart as before:

Staffan_0-1620644976133.png

 

 

 

Taoufiq_Zarra

@Staffan  can you share a sample data ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Staffan
Contributor II
Contributor II
Author

Sure - as you can see, the data set is very simple. Just Date and Visits for april 2020 and april 2021:

Staffan_0-1620645498532.png

 

Taoufiq_Zarra

@Staffan  if I understood correctly

you have or you  add in script Day(Date) as DAY and year(Date) as YEAR

in the UI

dimension DAY

measures:

1->=Sum({<YEAR = {"$(=Max(YEAR))"} >} Visits)

2->=Sum({<YEAR = {"$(=Max(YEAR)-1)"} >} Visits)

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉