Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
wanass123
Contributor III
Contributor III

Month diff

Please assist me in determining how to correct the month difference because it displays incorrect numbers because it is not linked to the year; please demonstrate how to link the date with the year in order to display the correct month difference for previous months. 

Current result : 

Monthidff Monthname(Payment_date)
-7 Sep-22
-8 Oct-22
-9 Nov-22
-10 Dec-22
1 Jan-23
0 Feb-23

 

Expected result : 

 

Monthidff Monthname(Payment_date)
5 Sep-22
4 Oct-22
3 Nov-22
2 Dec-22
1 Jan-23
0

Feb-23

Labels (2)
2 Replies
E_Røse
Creator II
Creator II

Try this:

 

= num(month(Date)) -month(today(1))
+12*(year(Date)-year(today(1)))

 

today(1) returns the date of the function call, while today() returns the date of last reload. You might prefer one over the other. If you want use date of last reload, it is better to create a variable in the load script like this

Let vToday =today();
Let vCurrentMonth = Month(vToday);
Let vCurrentYear = Year(vToday);

and use the follwoing expression:

 

= num(month(Date)) -vCurrentMonth
+12*(year(Date)-vCurrentYear)

 

Please like and mark my answer as a solution, if it resolved your issue.

 

Gabbar
Specialist
Specialist

As i see here you are going backwards from current month to your month name.
try using this expression:
A:
load *, ((year(latest_date)*12) + num(month(latest_date)))-((year(Date)*12)+num(month(Date))) as MonthiDiff
load *,
MonthStart(Date(Date#(Monthname,'MMM-YY'),'YYYY-MM-DD')) as Date,
monthstart(date(Today(),'YYYY-MM-DD')) as Latest_Date  from (Source);