Skip to main content

Notifications

Community site session details
Power Automate - Building Flows
Answered

How to get the current week number in Power Automate?

Like (0) ShareShare
ReportReport
Posted on 19 Feb 2025 14:06:56 by 16

Hi everyone,

I'm trying to get the current week number in Power Automate (cloud), but I keep running into issues with invalid expressions. I tried using but all are wrong

formatDateTime(utcNow(), 'ww') = semaine "ww" (wrong)
add(div(dayOfMonth(utcNow()),7),1) = semaine 3 (wrong)
add(div(dayOfMonth(utcNow()),7),0) = semaine 2 (wrong)
add(div(dayOfYear(utcNow()),7),1)= semaine 2 (wrong)

However, this doesn't seem to work as expected. It either returns "ww" as text or causes an error.

Does anyone know the correct expression to get the current week number in Power Automate? Ideally, I want a simple and reliable solution that works within a Compose action.

I ask ChatGPT et Copilot to help me but they didn't find (i try youtube too but the same thing, nothing works)

Thanks in advance!

  • David_MA Profile Picture
    10,790 Super User 2025 Season 1 on 25 Feb 2025 at 14:40:17
    How to get the current week number in Power Automate?
    I generated a new spreadsheet with the three expressions in this conversation:
    1. ISO format provided by @Chriddle: if(less(div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7),1),if(or(and(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),4),0),not(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),100),0)),equals(dayOfWeek(concat(string(sub(int(formatDateTime(outputs('Date'), 'yyyy')),1)),'-01-01')),3)),and(not(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),4),0)),equals(dayOfWeek(concat(string(sub(int(formatDateTime(outputs('Date'), 'yyyy')),1)),'-01-01')),2))),53,52),if(greater(div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7),if(or(and(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),4),0),not(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),100),0)),equals(dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),3)),and(not(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),4),0)),equals(dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),2))),53,52)),1,div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7)))
    2. Saturday start from Jan 1: formatNumber(add(div(sub(dayOfYear(outputs('Compose_Today')), dayOfWeek(outputs('Compose_Today'))), 7), 1), '00')
    3. Sunday start from Jan 1: formatNumber(add(div(sub(dayOfYear(outputs('Compose_Today')), dayOfWeek(outputs('Compose_Today'))), 7), 2), '00')
    If you get different results than what is in the attached spreadsheet, I don't have an explanation unless it has to do with regional settings or something. Since Power Automate doesn't have a built-in expression to return the week number, we need to use expressions that may not be perfect.
     
    ​​​​​​​There is this post in the Power Automate ideas channel: How to calculate week number in a year in flows? · Community. I would suggest up-voting this idea and maybe one day we'll get a weeknumber expression we can use.​​​​​​​
  • CF-19021403-0 Profile Picture
    16 on 25 Feb 2025 at 08:34:46
    How to get the current week number in Power Automate?
    Hi,
     
    I try today, and i have "Week 9"
     
    So i think ,it change the number of week the thuesday
  • CF-19021403-0 Profile Picture
    16 on 24 Feb 2025 at 09:54:01
    How to get the current week number in Power Automate?
    Hi,
     
    I make a test this mornig, and i still have "Week 8" 
     
    I used "formatNumber(add(div(dayOfYear(utcNow()),7),1),'00')"
     
    I will try tomorrow, maybe i will have "Week 9"
     
     
  • Chriddle Profile Picture
    7,685 Super User 2025 Season 1 on 21 Feb 2025 at 14:20:09
    How to get the current week number in Power Automate?
    Here is the reference:
     
    But I was wrong too ;)
    The return code is not 25, but 21.
    Excel corrected this automatically (I hate this behaviour), so I didn't notice.
  • David_MA Profile Picture
    10,790 Super User 2025 Season 1 on 21 Feb 2025 at 13:01:49
    How to get the current week number in Power Automate?
    @Chriddle there are definitely variations around the world on which day is the first day of the week. But there is a difference between the WEEKNUM and ISOWEEKNUM functions in Excel. WEEKNUM always considers the start of the year as January 1, while ISOWEEKNUM considers it to be the first week with a Thursday.
     
    I could not find a direct Excel reference from Microsoft, but I found this reference that explains this: WEEKNUM vs. ISOWEEKNUM: What's The Difference in Excel?. However, Microsoft does explain the difference here: WeekNum and ISOWeekNum functions - Power Platform | Microsoft Learn. The MS reference also shows how to set which day of the week you want to start the weeks on.
     
    The attached spreadsheet I generated using your ISO expression to generate the week number and then added columns with WEEKNUM and ISOWEEKNUM to highlight the differences.
  • Chriddle Profile Picture
    7,685 Super User 2025 Season 1 on 21 Feb 2025 at 08:33:48
    How to get the current week number in Power Automate?
    @CF-19021403-0
    It depends. There are differences in the definition of week number around the world.
    For the US this should be fine: formatNumber(add(div(sub(dayOfYear(utcNow()), dayOfWeek(utcNow())), 7), 2), '00')
    But in Europe my expression below is the right way.
     
    @David_MA
    WEEKNUM([@Date];25) and ISOWEEKNUM([@Date]) do the same (although ISOWEEKNUM([@Date]) seems preferable)
  • David_MA Profile Picture
    10,790 Super User 2025 Season 1 on 20 Feb 2025 at 15:47:07
    How to get the current week number in Power Automate?
    Re: Excel supports ISO 8601 week numbers: =WEEKNUM([@Date];25)
     
    Except the function in Excel for ISO week numbers is =ISOWEEKNUM([@Date]) instead.
  • CF-19021403-0 Profile Picture
    16 on 20 Feb 2025 at 14:55:34
    How to get the current week number in Power Automate?
    Thanks @David and @Chriddle
     
    So can i write this ? ( i change "outputs('Compose_Today') by (utcNow() ")
     
    formatNumber(add(div(sub(dayOfYear(utcNow(), dayOfWeek(utcNow()), 7), 2), '00')
     
    Our weeks begins at Monday
  • Chriddle Profile Picture
    7,685 Super User 2025 Season 1 on 20 Feb 2025 at 14:33:14
    How to get the current week number in Power Automate?
    Excel supports ISO 8601 week numbers:
    =WEEKNUM([@Date];25)
     and the first day of the week is Monday ;)
  • David_MA Profile Picture
    10,790 Super User 2025 Season 1 on 20 Feb 2025 at 14:12:10
    How to get the current week number in Power Automate?
    As @Chriddle pointed out this does not return an ISO week number. In fact, the expression below considers the start of the week a Saturday. If you want the start of the week to be Sunday so it at least aligns with the Excel =WEEKNUM([@Date]) function, you need to use this expression:
     
    formatNumber(add(div(sub(dayOfYear(outputs('Compose_Today')), dayOfWeek(outputs('Compose_Today'))), 7), 2), '00')
     
    Replace outputs('Compose_Today' with your date value. I created a flow to output this for one year and to confirm this expression aligns with the Excel formula.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard
Loading started
Loading started