Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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!

22 Replies
edwin
Master II
Master II

i meant use it in your expression i thought you were using it in a text box?:
=sum({<Anno={$(=max(Anno))} , seg={'+'}>}Netto) -
sum({<date01={">=$(=addyears(yearstart(today()),-1))<=$(=addyears(today(),-1))"}, seg={'+'}>}Amount)

 

danimarc12
Partner - Creator
Partner - Creator
Author

There's something which's not working. The second term, sum({<data01={">=$(=addyears(yearstart(today()),-1))<=$(=addyears(today(),-1))"}, segno={'+'}>} Netto), gives me back " 0,00€" instead of the "Netto" of the previous year

edwin
Master II
Master II

see how it is used in my sample.

there may be something else going on with other fields in your data model.  could it be there is no Seg=+ in prior year?  maybe attaching a QVW would help in trouble shooting your issue.  but the suggested expression should work ofr the requirements you gave,

edwin
Master II
Master II

as a way to figure out what is going on try this first:

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

or  sum({1<Anno={2019}}>} Netto)

this will ignore all selections and let you check if there are indeed values for last year period to same date last year or just for 2019.  before remove the 1 identifier from your set analysis, look at what is currently selected then go from there

danimarc12
Partner - Creator
Partner - Creator
Author

img2.PNGimg1.PNG

This is the situation 🤔 I have to see something, not "0", haven't I?

edwin
Master II
Master II

can you pls try this:

sum({1<data01={">=1/1/2019<=11/26/2019"}>} Netto)

assuming your date format M/D/YYYY

 

edwin
Master II
Master II

Also, can you pls list both Anno and data01?  pls select 2019 in Anno and see what values are selectable in data01.

there is nothin wrong with the set analysis phrase 
{">=$(=addyears(yearstart(today()),-1))<=$(=addyears(today(),-1))"}
so there is something else affecting your sum 

danimarc12
Partner - Creator
Partner - Creator
Author

Cattura.PNGCattura2.PNG

This is what i see.. I can't understand what's going wrong!

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)

edwin
Master II
Master II

just make sure the brackets are in the right places.  i just typed it without carefully checking the bracket placements