Skip to Content
author's profile photo Former Member
Former Member

Last Month DAY() in Formula

I am trying to write a formula that uses a date parameter selected by the user to calculate a Last Month's MTD total. I am having trouble setting up the formula to handle when the dates are not in the same day range. For example, the parameter is 07/31/2016, but there is only 30 days in June (last month).

Parameter Date: 07/31/2016 ({?EndDate})


If DATE({date field}) >= DATE(YEAR({?EndDate}), (MONTH({?EndDate})-1,1) and

DATE ({date field}) <= DATE(YEAR({?EndDate}), MONTH({?EndDate}),1)-1) then

Result I want:

Data from range 06/01/2016 to 06/30/2016

The above formula will not work when the Parameter date is today's date. How can I change the formula to make it work for all instances? Thank you.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 11, 2016 at 08:18 PM

    We can get previous month first/last day as mentioned below


    dates.PNG (8.0 kB)
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 11, 2016 at 05:03 PM

    Hi,

    Try:

    If Date({date fied}) IN Date(DateAdd('m', - 1, {?EndDate}- Day({?EndDate})) + 1) TO

    Date({?EndDate}- Day({?EndDate}))) then

    -Abhilash

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I tried this, but I get the error "keyword 'then' is missing" even though it is there after the ")". Not sure why I am getting that message. If I reduce the ")", then I get the message that "A date-time is required here" highlighting after the "TO".

  • Posted on Aug 11, 2016 at 05:05 PM

    Your formula also doesn't account for different years if, for example, the value of {?EndDate} is 1/31/2016. So, I would try something like this:

    Datevar endDt := {?EndDate}) - Day({?EndDate}); <--Gives the end day of the previous month

    DateVar startDt := Date(Year(endDt), Month(endDt), 1); <--Gives the first day of the previous month

    If Date({Date Field}) >= startDt and Date({Date Field}) <= endDt then...

    -Dell

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.