Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
Creator III
Creator III

Calculated value in set analyis

I have a field called Year which uses the format YYYY-YY (e.g. 2010-11) - this cannot be changed

I also have a chart showing average values with the dimension as year and expression 'AVG(Value)'

What I would like is to create a chart, still with dimension as year, but the expression should be the average value for that year, minus the average value for the previous year:

AVG(Value) - AVG(PreviousValue)

How can I get Qlikview to recognise the previous value?

I can calculate the previous year using the following syntax:

=(LEFT(Year,4)-1) & '-' & (RIGHT(Year,2)-1)

So I want something like:

AVG(Value) - AVG({<Year={'(LEFT(Year,4)-1) & '-' & (RIGHT(Year,2)-1)'}>} Value)


But that doesn't work at all!!


UPDATE


I have added a new field in the script which I'm hopeful will simplify this, call 'StartYear' which is just the YYYY of 'Year'.


My table looks like this:

  

StartYearValue
20090.898432863
20100.905835632
20110.882654745
20120.903658664
20130.930024836
20140.940725491
20150.92200804
20160.896753071
20170.900086453


What I want now is an expression which calculated the difference between Value and the value of the previous year.


So:

Avg(Value) - Avg({<StartYear={'StartYear-1'}>} Value)


But that doesn't work...


How do I amend the second part of my expression so that it looks at the previous year?


Message was edited by: Jessica Webb

24 Replies
jessica_webb
Creator III
Creator III
Author

Thanks Kushal - that's worked

jessica_webb
Creator III
Creator III
Author

Thanks Andrew - you haven't misunderstood! That's exactly what I was looking for (although Kushal got there just before with a similar answer).


I'm a bit unsure about the 'above' function so just reading up on it to make sure it'll work in all my scenarios (as I'm rarely using straight tables).

Are you able to elaborate on the difference between the two correct answers I got?

Avg(Value) - above(total Avg(Value))

compared to

rangesum(Avg(Value),-Above(Avg(Value)))

Kushal_Chawda

No problem

effinty2112
Master
Master

Hi Jessica,

Rangesum has the advantage over a regular summation in that it won't fall down if one of the arguments is null.

if B is null then

Rangesum(A,B) = A , but A+B  will be null.

Cheers

Andrew

jessica_webb
Creator III
Creator III
Author

Thanks Andrew. That's a big help.

I think in my scenario then I would want to go for a regular summation as if there is no data for a previous year, then the value should show as null.

Really useful to know!