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: 
Syahfira1
Contributor III
Contributor III

How to get previous month date ?

Hello,

How I can get previous month date when the user select a specific date?

My data has reporting date column. This reporting date column will have

  • mid month date which is every 15th of the month
  • month end date of the month

My user would like to compare the sales of the date selected with the previous month date.

So,

  • when they select 15th June , they will see 15th May for the comparison.
  • when they select 30th June, they will see 31st May for the comparison.

I have managed to get for the mid month but when it comes to the month end, it will show me the exact date but not the exact date of the previous month end date.

  • when they select 30th June, they  see 30th May instead of 31st May

How I can fix and make set analysis for this?

This is my current set analysis

  • sum({<[Reporting Date.MasterCalendar.Date]={"$(=date(addmonths(vLatestDate,-1)))"}>}[Past Due])
  • vLatestDate variable = date(max([Reporting Date.MasterCalendar.Date]

Help is much appreciated.

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Set the AddMonths third "mode" parameter to 1. 

addmonths(vLatestDate,-1, 1)

=AddMonths('6/30/2022',-1, 1)  = 5/31/2022

See the help for AddMonths:
https://help.qlik.com/en-US/sense/August2022/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeF...

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

4 Replies
BrunPierre
Partner - Master
Partner - Master

This is the dynamic expression for the same period last month

=AddMonths(Max(Date), -1)

Syahfira1
Contributor III
Contributor III
Author

Hey,

Thank you.

But, I am using the suggested formula currently which is not fulfilling what I am looking for.

BrunPierre
Partner - Master
Partner - Master

Could you provide specifics as to why it's not working for you or possibly give sample data?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Set the AddMonths third "mode" parameter to 1. 

addmonths(vLatestDate,-1, 1)

=AddMonths('6/30/2022',-1, 1)  = 5/31/2022

See the help for AddMonths:
https://help.qlik.com/en-US/sense/August2022/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeF...

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com