0

Creating "1st Month of the Year of the Previous Month" in a list

I have the following as a Range List which is the *First Month of Current Year* until previous month

 

I want to change the start of the list to be the first month of the previous year instead.

For example - when we get to Jan 2024, I want the list to be 202301-202312 - it is functional in its' current fomruntil Jan

{Range(StrToMember([Account Month].[Account Month],DateFormat(dateTime(), "YYYY")+"01"),lag(StrToMember([Account Month].[Account Month],DateFormat(dateTime(), "YYYYMM")),1))}
 

 Is there a way to do this?

 

Thanks,

Satveer

4 replies

null
    • imbarmarinescubar_pyram
    • 1 yr ago
    • Official response
    • Reported - view

    Hi  ,

    You could do something like this:
     

    round(dateformat(datetime(),"YYYY")-1)+"01"

    Similar to what you already have, just substracting 1 from the year and ensuring you don't have any ".0" generated in the automatic type casting (you can see we are jumping between text and number over and over again).

    you could also use lag(12) to go 12 months backwards, assuming all the months exist in your data.

      • Satveer_Kaur
      • 1 yr ago
      • Reported - view

       Hi,

       

      Thanks a lot for getting back.

       

      Sorry, I think I should have been clearer

      I don't want the 1st month of the previous year, but the 1st month of the "year of the previous month". So for Feb to Dec, it will be Jan of the current year, but for Jan it was be Jan of the previous year

      • imbarmarinescubar_pyram
      • 1 yr ago
      • Reported - view

       

      You can use the addmonths function to get the previous month (would return Dec 2022 give Jan 2023)


      dateformat(addmonths(datetime(), -1),"YYYY")+"01"

       

      • Satveer_Kaur
      • 1 yr ago
      • Reported - view

       Hi - that works, thanks!

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 4Replies
  • 67Views
  • 2 Following