Search code examples
power-automateweek-number

How to find week number for the previous week in Power Automate?


I have used this formula:

add(div(dayOfYear(utcNow()),7),1) 

to calculate the week number of the current date. It works well. However, I actually need the week number of the previous week, because even though I am sending the report today the data is about last week. How to achieve this?

For example the week number of 14.12.2023 should be 50 and previous week should be 49.


Solution

  • I'm not going to question the current logic if you're happy with it, I'm just going to suggest an approach for getting the previous week.

    You can always use a sub() expression to minus one from the current derived week but when you get to the end of the year, you need if statements to work out where you are in time if you're in the first week.

    I suggest replacing utcNow() with addDays(utcNow(), -7) so that it goes back 7 days in the calendar and then works out the weeks from that date.