Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Date column last x months

Hello everyone,

 

I have created a calculated column which filters the most recent months, in this particular example the last two months. This filter was working, but only in the year itself. Now we are in the new year, it shows only the month of this year, but it still want the months of 2021. So I want all the dates from 1 November till today (so the 4th of January). 

 

The formula is as follows:

Last 2 months = IF(OR(Month([Date])=Month(Today())-1, MONTH([Date]) =MONTH(TODAY())), "Last 2 months", BLANK())
 
How can this formula be adjusted that is returns also the months in the previous year? 
  • Anonymous's avatar
    Anonymous
    4 years ago

    Thank you amitchandak for your (fast) reply πŸ™‚

    The results I got were alle blanks, so I adjusted the formula as follows:

    Last 2 months = IF(OR(OR(EOMONTH([Date], 0) =EOMONTH(TODAY(), 0), EOMONTH([Date], 0) = EOMONTH(TODAY(), -1)), EOMONTH([Date], 0) = EOMONTH(TODAY(), -2)), "Laatste 2 maanden", BLANK())
     
    This resulted in the desired outcome.

2 Replies

  • Anonymous , better to use EOmonth to deal with months

     

    check one of three should work

     

    Last 2 months = IF(eomonth([Date],0)=eoMonth(Today(),-3)+1 && [Date] <=TODAY(), "Last 2 months", BLANK())

     

    or

    Last 2 months = IF(eomonth([Date],0)=eoMonth(Today(),-3)+1 && eomonth([Date],0) <=eomonth(TODAY(),0), "Last 2 months", BLANK())

     

    or

     

    Last 2 months = IF(eomonth([Date],0)=eoMonth(Today(),-3)+1 && eomonth([Date],0) <=eomonth(TODAY(),-1), "Last 2 months", BLANK())

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you amitchandak for your (fast) reply πŸ™‚

      The results I got were alle blanks, so I adjusted the formula as follows:

      Last 2 months = IF(OR(OR(EOMONTH([Date], 0) =EOMONTH(TODAY(), 0), EOMONTH([Date], 0) = EOMONTH(TODAY(), -1)), EOMONTH([Date], 0) = EOMONTH(TODAY(), -2)), "Laatste 2 maanden", BLANK())
       
      This resulted in the desired outcome.