Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Username
New Contributor

Last year calculations

Hello everyone,

I have an income statement in my Qlik Sense application.

I am able to calculate the percentage of the row value related to the revenue. Now i am trying to calculate the same percentage for last year but haven't been successful.

Here is the code for this year that works:

sum(Test11) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'}>} Test11)

So what is wrong with this script:

(sum({$<Vvvv = {$(=Only(Vvvv)-1)}>} Test11)) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'}>}{$<Vvvv = {$(=Only(Vvvv)-1)}>}Test11) 

 

1 Solution

Accepted Solutions
pradosh_thakur
Honored Contributor II

Re: Last year calculations

if vvv is year then 

(sum({$<Vvvv = {"$(=year(today())-1)"}>} Test11)) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'},Vvvv = {"$(=year(today())-1)"}>}Test11) 
Learning never stops.
5 Replies
arulsettu
Honored Contributor III

Re: Last year calculations

What is Vvvv ?

is that date field?

do you have year field?

Username
New Contributor

Re: Last year calculations

Ohh, sorry the explanation was incomplete. The Vvvv = year

pradosh_thakur
Honored Contributor II

Re: Last year calculations

Try something similar

 

Assuming you have a date field date1, you have to replace date1 with your date field 

 

sum({<date1={"=Year(date1)=year(today())-1"}>}Test11) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'},date1={"=Year(date1)=year(today())-1"}>} Test11)

Learning never stops.
pradosh_thakur
Honored Contributor II

Re: Last year calculations

if vvv is year then 

(sum({$<Vvvv = {"$(=year(today())-1)"}>} Test11)) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'},Vvvv = {"$(=year(today())-1)"}>}Test11) 
Learning never stops.
arulsettu
Honored Contributor III

Re: Last year calculations

Maybe like this

 

(sum({$<Vvvv = {$(=max(Vvvv)-1)}>} Test11)) / sum(TOTAL {$<[ReportLineDescription] = {'Revenue'}>}{$<Vvvv = {$(=max(Vvvv)-1)}>}Test11)