Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Sebastian_Dec
Creator II
Creator II

Year-on-year comparison Edit expression

Hi, I want to comparison year-on-year but not on Today() function but on specific user selection.

I load data (364 is days between 2022 vs 2023):

LOAD
date(hid_data) as Data,
date(hid_data - 364) as Data_LY,
sales

 

And in pivot table I want  to have comparison sales:

Selected date (its ok):

Sum({<Data = Data>} sales)

 

Previous date is not correct and I have error, can anyone help me what is bad? 😕

Sum({<Data = Data_LY>} sales)

I have "0", and should have values, when I write:

Sum({<Data = {'27.01.2022'}>} sales)
Sum({<Data = {'26.01.2023'}>} sales)

its ok.

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
Labels (3)
1 Solution

Accepted Solutions
Sebastian_Dec
Creator II
Creator II
Author

Ok, i use another method, a load calendar with dates and difference on days, and mark Date (Data) as Data-DifferenceDays.

Sum({<Data={"$(=Date(Max(Data)-DifferenceDays))"}>} sales)

 

I'm a bit surprised that I had to mess around like that, and Qlik doesn't have a similar option enabled by default...

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

3 Replies
md_talib
Contributor III
Contributor III

variables can be your solution.

2 for  Current Year 

vCalMinDate= Date(Min(Posting_Date),'DD/MM/YYYY')

vCalMaxDate=Date(Max(Posting_Date) ,'DD/MM/YYYY')

2 for Previous year 

vPYCalMinDate=Date(AddYears(Min(Posting_Date),-1),'DD/MM/YYYY') 

vPYCalMaxDate=Date(AddYears(Max(Posting_Date),-1),'DD/MM/YYYY')

Sebastian_Dec
Creator II
Creator II
Author

Ok, i use another method, a load calendar with dates and difference on days, and mark Date (Data) as Data-DifferenceDays.

Sum({<Data={"$(=Date(Max(Data)-DifferenceDays))"}>} sales)

 

I'm a bit surprised that I had to mess around like that, and Qlik doesn't have a similar option enabled by default...

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.
Sebastian_Dec
Creator II
Creator II
Author

@md_talib your suggestions were close, I can make variables in Lead editor like this:

LET Difference = 364;

And then on Edit expression:

Sum({<Data={"$(=Date(Max(Data)-$(Difference)))"}>} sales)

 

But its ok on 2022/2023, in other years the Difference could be different, especially in a leap year or some movable holidays if we have some other shifts in the calendar, in such an event loading the calendar for +20 years may be faster and safer.

 

This is just my opinion, maybe someone with more experience will know better...

Thanks & Regards,
Please close the thread by marking correct answer & give likes if you like the post.