Announcements
cancel
Showing results for
Did you mean:
Anonymous
Not applicable

Calculate the difference of months between dates

Hello! I am a beginner in Qlik Sense and would like to calculate the difference between dates as follows:

Pick the highest date recorded for the ID;

Calculate the difference of months with the current date.

ID
DATE (MM/DD/YYYY)
101/10/2017
104/19/2017
105/20/2017
202/10/2017
203/31/2017
209/17/2017

Assuming the current date is 12/4/2017 the expected result would be:

iDMax DateDifference Months
105/20/20176 Months
209/17/20173 Months

Tks

1 Solution

Accepted Solutions
Creator III

Hi,

Exp: =aggr(num((max(Date)-min(Date))/30,'#.##0 Months'),ID)

6 Replies

Perhaps this?

Dual((Num(Month(Today())) - Num(Month(Max(DATE)))) & '  Months', Num(Month(Today())) - Num(Month(Max(DATE))))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Specialist

HI,

I case you need this in the front end you could do this:

Dimension:

=AGGR(Max(ID),ID)

Measure1:

=Date(Max(TDATE))

Measure2:

=Round((Today()-Date(Max(TDATE)))/30,0.1) &' Months'

You'll need to clarify the algorithm to calculate months.

I hope this helps,

Cheers,

Luis

PS. When applicable please mark the appropriate replies as Correct. This will help community members know which discussions have already been addressed and have a possible known solution. Please mark replies as Helpful if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads as Helpful if you feel additional info is useful to others

Creator III

Hi,

Exp: =aggr(num((max(Date)-min(Date))/30,'#.##0 Months'),ID)

Anonymous
Not applicable
Author

Excellent tip! Thank you very much.

If the month difference appears as negative, how do I always leave positive?

In some results the information appeared like this:

- 1 Months

May be look for Fabs() in help.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Thank you! This suggestion met my need. I'll test the others for knowledge. Thank you all.