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

Announcements
Only at Qlik Connect! Guest keynote Jesse Cole shares his secrets for daring to be different. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
SJ_16
Contributor II
Contributor II

Automate Formula

Hi,

Any idea how I can automate the formula below please so I don't have a hard coded date? This will always look at previous year.

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='2017'
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='2017'
and Lookup='due for renewal' ,Val)),0, RowNo()))

11 Replies
Somasundaram
Creator III
Creator III

Hi,

 

Using Addyears() function we can add years/ subtract years. 

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=Year(AddYears(DATE,-1))
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=Year(AddYears(DATE,-1))
and Lookup='due for renewal' ,Val)),0, RowNo()))


-Somasundaram

If this resolves your Query please like and accept this as an answer.
SJ_16
Contributor II
Contributor II
Author

Thanks, but this doesn't work as my line on my line chart now disappears.
Somasundaram
Creator III
Creator III

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=Year(AddYears(DATE_IN,-1))
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=Year(AddYears(DATE_IN,-1))
and Lookup='due for renewal' ,Val)),0, RowNo()))

-Somasundaram

If this resolves your Query please like and accept this as an answer.
SJ_16
Contributor II
Contributor II
Author

Still get the same result, the line disappears
Somasundaram
Creator III
Creator III

Use this one ---------- num(Year(AddYears(DATE_IN,-1)))
hope it will help.

-Somasundaram

If this resolves your Query please like and accept this as an answer.
SJ_16
Contributor II
Contributor II
Author

Still doesn't work unless I have added it incorrectly?

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=num(Year(AddYears(DATE_IN,-1)))
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)=num(Year(AddYears(DATE_IN,-1)))
and Lookup='due for renewal' ,Val)),0, RowNo()))
Somasundaram
Creator III
Creator III

If possible can you share the app?

-Somasundaram

If this resolves your Query please like and accept this as an answer.
ahmed_hassan
Contributor III
Contributor III

 HI,

The best way to do it is by creating 2 variables.  You can type the following code in the script or do it manually.

Set vMaxyear = 'Max(Year(DateField))';
Set vPreyear = 'Max(Year(DateField)-1)';

and then try:

 

RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='$(vPreyear)'
and Lookup='Renewal_Value',Val)),0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}>}if(Left(DATE_IN,4)='$(vPreyear)'
and Lookup='due for renewal' ,Val)),0, RowNo()))

 Good luck!

 

sunny_talwar

Why don't you use set analysis here

RangeSum(Above(Sum({<[Country] = {'UK'}, DATE_IN_YEAR = {"$(=Max({1}DATE_IN_YEAR)-1)"}, Lookup = {'Renewal_Value'}>} Val), 0, RowNo()))
/
RangeSum(Above(Sum({<[Country] = {'UK'}, DATE_IN_YEAR = {"$(=Max({1}DATE_IN_YEAR)-1)"}, Lookup = {'due for renewal'}>} Val), 0, RowNo()))

Where DATE_IN_YEAR is created in the script like this

LOAD ...,
 DATE_IN,
 Year(DATE_IN) as DATE_IN_YEAR
FROM ...;