In this post, it will show and explain the expression to return the last month as a string which you can find below:
if(month([Date])-1 = 0, string(year([Date])-1) + '-12', string(year([Date])) + '-' + if(month([Date])-1 < 10, '0', '') + (month([Date])-1))
To break this down it would be useful to simplify it in a more readable form:
IF month before is 0 (December):
string(year before) + '-12'
string(year) + '-' + IF month before is less then 10 (October) return 0 ELSE nothing + month before
Example: 2022-01, the if statement is used to append the 0 to the month to prevent the string looking like 2022-1
Please sign in to leave a comment.