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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Number of Month between today and a Date into a field

Hello,

I would like to take the number of months between today and the Date selected into the field named 'Value Date'.

Capture.PNG

How can i do that please ?

Thank you in advance for your help,

Sébastien.

5 Replies
sunny_talwar

sunny_talwar

You can try this:

=((Year(Today(2)) * 12) + Month(Today(2))) - ((Year(Max([Value Date])) * 12) + Month(Max([Value Date])))

Anonymous
Not applicable
Author

Thanks a lot for your response, but it doesn't return the correct answer :

Here the field and the result:

Capture.PNG

The Expression:

= ((Year(Max([AIR Import Data]) * 12) + Month([AIR Import Data])))

==> the field [AIR Import Data] is named Value Date here

So the final calculus is wrong:

Capture.PNG

The Expression:

=((Year(Today(2)) * 12) + Month(Today(2))) - ((Year(Max([AIR Import Data]) * 12) + Month([AIR Import Data])))

Do you have an idea of the problem ?

Thank you in advance for your return,

Sébastien.

sunny_talwar

Can you try this, I made a mistake earlier:

=((Year(Today(2)) * 12) + Month(Today(2))) - ((Year(Max([AIR Import Data])) * 12) + Month(Max([AIR Import Data])))

swuehl
MVP
MVP

You can also have a look at

Calculating Months difference between two dates

There is a description of an approach to define this using a variable, and also to consider the days (similar to the Age() function for years), so that End of this Month to Beginning of next month could equal to zero, not 1.

SET MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + 1);


or

SET MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + If(Day($1)>Day($2),0,1));


-->

=$(MonthDiff(Max([Value Date]), Today()))