1

How to find the "1st Month of the Year of the Previous Month" in a list

How to find the "1st Month of the Year of the Previous Month" in a list

In this question the user was asking how to find the first month of the year, but the basis for this search would not be the current month, but the month before. While in 11 out of 12 cases this would be obvious - January of the current year. But for any January the previous month is December, and therefore the 1st Month of that year is the previous Years January. So how can this be solved. 

Sidenote:

if you are looking for this years first month, this could look like this:
 

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

Similar to what you already have, just subtracting 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).

But what if, as described above you need this to jump for one year when its January

More on round in our Help Pages

Solution

If you 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. Then you would use the addmonths function to get the previous month (would return Dec 2022 give Jan 2023)

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

This way you move 'backwards' and then use the formula above to get the first month of the year as previously mentioned.

More on dateformat in our Help Pages

If you have questions about this solution, please let us know below.

 

Reply

null