Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
danimarc12
Partner - Creator
Partner - Creator

Compare a period this year with the same period last year

Hello Everyone!

I have a little problem with the following expression:

img.PNG

I want to calculate the difference between the "Netto" of a period compared to the "Netto" of the same period of the previous year but I don't know how to do that. Please, could anyone text me the right expression?

Thanks!

1 Solution

Accepted Solutions
edwin
Master II
Master II

that exposes an important detail - your date is a time stamp.  therefore comparing it with a date will not work. try this:



sum({1<data01={">=$(=timestamp(addyears(yearstart(today()),-1)))<=$(=timestamp(addyears(today(),-1)))"}>} Netto)

View solution in original post

22 Replies
edwin
Master II
Master II

its a little bit obvious but have you tried 
sum({<Anno={$(=max(Anno)-1)}, seg={+}>}Netto)

assuming seg drives the period within the year

danimarc12
Partner - Creator
Partner - Creator
Author

Hi Edwin, Thanks for your answer.

The problem is that your expression calculates the "Netto" of the whole previous but I want to calculate the "Netto" until the date of Today in the previous year.

edwin
Master II
Master II

this assumes that no date is selected.  if a date is selected, then that needs to be added in the set analysis modifiers as Date= (for example)

edwin
Master II
Master II

in that case you can add in your set analysis for the prior year component

date={"<$(=addyears(today(),-1))  // date is your date field

this limits the data set to before same date last year, combined with the year = prior year that should cover it

edwin
Master II
Master II

didnt see the date field:

sum({<Anno={$(=max(Anno)-1)}, date01={"<$(=addyears(today(),-1))"} , seg={+}>}Netto)

edwin
Master II
Master II

one more time: 

sum({<Anno={$(=max(Anno)-1)}, date01={"<=$(=addyears(today(),-1))"} , seg={+}>}Netto)

edwin
Master II
Master II

another form:

=sum({<date01={">=$(=addyears(yearstart(today()),-1))<=$(=addyears(today(),-1))"}>}Amount)

danimarc12
Partner - Creator
Partner - Creator
Author

Do I have to set it in the script?

danimarc12
Partner - Creator
Partner - Creator
Author

I think I have to make an Aggregation but I don't know how to write it.
I have to write something like :

Sum( if ( InYearToDate ( data01, Max(data01), -1 ) and segno = '+', Netto ))

Could anyone tell me how to write it correctly?