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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Number of years / AddYears function

I'm looking at the AddYears() function - and trying to calculate the number of years an application has been active (Effective Date). 

Date(AddYears(Effective Date, 0), 'YYYY' - I'm trying to think of the logic to be able to display as such:

within one year of current date = 0

greater than one year, less than 2 = 1

and so on - what function(s) do I need to set up in the script?

Thanks in advance

1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

To calculate number of months you can use

=((Year(EndDate) * 12) + Month(EndDate)) - ((Year(StartDate) * 12) + Month(StartDate))

divide this by 12 and use as you need.

You can use it as function also like

SET MonthDiff = Num(((Year($2) * 12) + Month($2)) - ((Year($1) * 12) + Month($1)));

then you can use this as

$(MonthDiff(startdate, enddate)) to compute.

View solution in original post

1 Reply
CELAMBARASAN
Partner - Champion
Partner - Champion

To calculate number of months you can use

=((Year(EndDate) * 12) + Month(EndDate)) - ((Year(StartDate) * 12) + Month(StartDate))

divide this by 12 and use as you need.

You can use it as function also like

SET MonthDiff = Num(((Year($2) * 12) + Month($2)) - ((Year($1) * 12) + Month($1)));

then you can use this as

$(MonthDiff(startdate, enddate)) to compute.