Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
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

21 Replies
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") 😉
Staffan
Contributor II
Contributor II
Author

Yes, here is how it looks now in my UI:

Staffan_0-1620647681542.png

My goal is to compare -day by day- the month of april 2020 with the month of april 2021. Maybe I would be better off restructuring my data set, but it would be interesting to see if it can be solved with this type of data.

Taoufiq_Zarra

@Staffan  in dimension change DATE.DATE to =day(DATE.DATE)

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

@Taoufiq_Zarra Ok, that cleaned up the chart! But there is still only one line:

Staffan_0-1620648751859.png

 

 

Taoufiq_Zarra

do you have a YEAR field in your data model ? if not you can create in your script

something like

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

2->=Sum({<DATE.YEAR= {"$(=Max(DATE.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

I only have two columns: Date and Visits. Like this:

Staffan_0-1620649533468.png

And I have added your two suggestions as measures:

Staffan_1-1620649611676.pngStaffan_2-1620649645714.png

 

Taoufiq_Zarra

@Staffan  or you can change measure to :

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

2->=Sum({<Date = {">=$(=Max(Addyears(YearStart(Date),-1))) <=$(=Max(Addyears(YearEnd(Date),-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

Almost there 🙂 It looked like it worked for a second, then the layout changed to this:

Staffan_0-1620651824621.png

Taoufiq_Zarra

Oh yes its me

can you share a sample data in excel format or csv

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

Yes, here you go