Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Calculate sum for last year

I have the following expression to calculate

Date is in format YYYYMMDD

Sum({$<Date = {">=$(=vStartDate)<=$(=vEndDate)"}>} Target)

How to calculate the same but for the last year

I try  Sum({$<Date = {">=$(=vStartDate)-1<=$(=vEndDate)-1"}>} Target)

but it doesn(t work how to correct it ?

1 Solution

Accepted Solutions
sunny_talwar

May be this:

Sum({$<Date = {">=$(=Date(AddYears(vStartDate, -1), 'YYYYMMDD'))<=$(=Date(AddYears(vEndDate, -1), 'YYYYMMDD'))"}>} Target)

View solution in original post

3 Replies
sunny_talwar

May be this:

Sum({$<Date = {">=$(=Date(AddYears(vStartDate, -1), 'YYYYMMDD'))<=$(=Date(AddYears(vEndDate, -1), 'YYYYMMDD'))"}>} Target)

Digvijay_Singh

Something like this -

Sum({<Year=, Quarter=, Month=, Week=, Date={">=$(=YearStart(Max(Date), -1))<=$(=AddYears(Max(Date), -1))"}>} Sales)

ali_hijazi
Partner - Master II
Partner - Master II

is your date field interpreted as number in qlik if so then you need to do the following:

create two variables vStartLastYear and vEndLasYear

vStartLastYear would be = numDaystart(addYears(date($(vStartDate)),-1))

vEndLastYear would be = numDaystart(addYears(date($(vEndDate)),-1))

in your expression you would use these new variables and you ignore selections on date parts (year=, month=,etc...)

I can walk on water when it freezes