Hi, @kouliscon
I think @Mira_Ghaly 's solution is probably better than mine, but I wanted to put all the logic out using pure actions (ish).
Once you have this down, sliding much of it into expressions and functions will slim it down considerably, but this plots out the logic easily.
I won't explain all of the actions here, because they're all pretty standard, the only tricky one is DO UNTIL which can sometimes be a little funny. If you can't get into the value side of the DO UNTIL, click "Edit in advanced mode" then click back to basic and it will open it up.
However if anything looks odd, please say. ... ... Especially if I'm wrong. 😅
Explanation
- Count up the days until it is next Month.
- Then count back the days until you reach a Monday.
Full Flow
Full Flow
Broken Down
Variables
Do Until Next Month
Do Until Is Last Monday
Define Monday
Some of the Simple Expressions for Copy/Paste
None of the expressions used here will be alien to a flow user after a few uses, I don't think.
timeVAR
This might sound silly to explain, but it's needed because it needs to continually be used and reset. Additionally it gives an easy reference for any expressions
nxtMthVAR Expression
int(formatDateTime(body('Add_a_month'), 'MM'))
Firstly this formats the date and time of the "Add a month" action before into to numbers (eg: 07).
Secondly this ensures that when it presents that '07' it is definitely presented as an integer type of number.
monthVAR Expression
int(formatDateTime(body('Add_a_day'), 'MM'))
This is nearly the same expression as the nxtMthVAR, so it's basically picking out the numeric representation of whatever month the day addition has brought the flow into.
Condition to check if it's next month
This just looks to see if the number that you just generated in monthVAR is the same as the one that you worked out in nxtMthVAR at the very start.
If the numbers match, the nxtMthMatchVAR is set to 'true', and the DO UNTIL will not iterate again.
dayVAR Expression
formatDateTime(variables('timeVAR'), 'dddd')
This simply takes the time from timeVAR and displays the day as a word, in full (eg: Monday).
Condition to check if it's Monday
This now checks to see if the day that you just generated in dayVAR is 'Monday'.
If it is, then the isMonVAR is set to 'true', and the DO UNTIL will not iterate again.
lastMondayOfThisMonthVAR
This can now simply be set to the timeVAR which has now been wound forward, then back, until it is the right day!