As you can see in the image above; June 2017 considered as fiscal year 2017. However, July 2017 is part of fiscal year 2018. So the simple logic can be like this:
if (calendar month >= fiscal year start)
then fiscal year = calendar year
else fiscal year = calendar year + 1
This code is pseudo code. don’t write that exactly in M! Let’s now implement it in M;
If you have to deal with multiple fiscal years (e.g., state and federal government fiscal years), the process is the same, only repeated.