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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
alex_202
Contributor II
Contributor II

How to properly utilize addMonths, addDate in qlik sense?

I came across qlik documentation and spot addMonths function. In my case, I have SQL line that I want to translate to qlik logic, and I don't see addDate function in qlik sense. I am wondering if qlik community help me to address my following problem.

 

Here is the sql line that I want to do same in qlik:

 

YEAR(LAST_DAY(DATEADD(MONTH,-1,CURRENT_DATE)))

YEAR(LAST_DAY(DATEADD(MONTH,-1,CURRENT_DATE)))

DATEADD('MONTH',-3,LAST_DAY(DATEADD(MONTH,-1,CURRENT_DATE)))

 

I read date and time function list on qlik help, and I think I might use daystart, dayend function, but I am still not sure how above sql lines can be properly translated to qlik logic. Can anyone in qlik community help me if there is workaround to do this? 

Labels (4)
1 Solution

Accepted Solutions
sasikanth
Master
Master

HI Alex, 

try this 

=AddMonths(MonthEnd(AddMonths(today(),-1)),-6)

View solution in original post

3 Replies
sasikanth
Master
Master

Try below exp,

= Year(MonthEnd(AddMonths(CURRENT_DATE,-1)))  

= AddMonths(MonthEnd( AddMonths(CURRENT_DATE,-1)),-3) 

    

Thanks, 

Sasi

 

 

 

 

Last Day :  MonthEnd(CURRENT_DATE)

Adding Months :  AddMonth(CURRENT_DATE,-1)

alex_202
Contributor II
Contributor II
Author

Thanks Sasi. However, based on your answer, I did this, do you mind to correct me:

 

in sql code: DATEADD('MONTH',-6,LAST_DAY(DATEADD(MONTH,-1,CURRENT_DATE)))

 

in qlik, I tried it as : AddMonths('MONTH',-6,MonthEnd(AddMonths(MONTH,-1,Date(Now()))))

 

I did also like this:

 

AddMonths(MonthEnd(AddMonths(MONTH,-1,Date(Now()))),'MONTH',-6)

 

which one would be correct one against sql line that I put? is that correct way to do so? any idea?

sasikanth
Master
Master

HI Alex, 

try this 

=AddMonths(MonthEnd(AddMonths(today(),-1)),-6)