cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nagaraj007
Post Patron
Post Patron

GET WEEK NUMBER FROM CURRENT DATE

Hello All,

 

I would want some help to get the week number of current date. I have added the below function to get the current date. If some one could help me to get the week number it would be of great help.

 

convertFromUtc(utcNow(),'India Standard Time','dd/MM/yyyy')
26 REPLIES 26
Pstork1
Most Valuable Professional
Most Valuable Professional

Try this formula

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

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
CFernandes
Most Valuable Professional
Most Valuable Professional

@nagaraj007 

 

@Pstork1  formula works 🙂

 

You can also find some more ideas in the comments for the thread, https://powerusers.microsoft.com/t5/Power-Automate-Ideas/How-to-calculate-week-number-in-a-year-in-f... 

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Will it work for all years? As I saw in one of the forums the below function works only for 2019. Please confirm. @Pstork1 

Pstork1
Most Valuable Professional
Most Valuable Professional

The function should work for any year.  It is currently based on UTC.  If you want it for India time zone then use this one.

add(div(dayOfYear(convertFromUtc(utcNow(),'India Standard Time','U')),7),1)

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Amanthaper
Responsive Resident
Responsive Resident

edited -

Does this also work on Power Automate Desktop?

Pstork1
Most Valuable Professional
Most Valuable Professional

Power Automate Desktop doesn't use the same functions as Power Automate, so no I don't think it will work.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
OliverR-82
Continued Contributor
Continued Contributor

It doesn't seem to work in 2021. It returns '21' for me today while we're currently in week 20, according to my calendar. I suppose I could replace the '1' in the formula with '2' but then it will likely not work correctly for next year, I would expect?

 

EDIT: or it could be because my calendar uses the ISO week number, which always starts on a Monday. That would explain. Unfortunately, that's the one I need. I'll try the method described here. It's more complex but if it does the job, then great.

ENRM
Helper III
Helper III

@nagaraj007 

Use the WeekNum and ISOWeekNum functions to determine the week number of a date.

These functions differ in how they determine the first week of the year (week 1):

  • WeekNum uses the week containing January 1 as the first week of the year. The result from this function can range from 1 to 54.

  • ISOWeekNum uses the week containing the first Thursday of the year as the first week of the year. This follows the ISO 8601 date and time standard definition for week numbering. The result from this function can range from 1 to 53. It is possible that 52 or 53 may be returned for the first days of January since the dates could belong to the last week of the previous year.

Use the second parameter to WeekNum to specify which day begins a week. You can provide either an Excel code number or use the StartOfWeek enumeration:


1, 17StartOfWeek.SundayWeek begins on Sunday. Default.
2, 11StartOfWeek.MondayWeek begins on Monday.
12StartOfWeek.TuesdayWeek begins on Tuesday.
13StartOfWeek.WednesdayWeek begins on Wednesday.
14StartOfWeek.ThursdayWeek begins on Thursday.
15StartOfWeek.FridayWeek begins on Friday.
16StartOfWeek.SaturdayWeek begins on Saturday.

 

ISOWeekNum always uses Monday as the start of the week. In Excel, the WeekNum function supports an addition code 21 that is not supported here; use ISOWeekNum instead.

If you pass a single number to these functions, the return value is a single result. If you pass a single-column table that contains numbers, the return value is a single-column table of results, one result for each record in the argument's table. If you have a multi-column table, you can shape it into a single-column table, as working with tables describes.

Syntax

WeekNum(DateTime [, StartOfWeek ])

  • DateTime - Required. Date/Time value to operate on.
  • StartOfWeek - Optional. Excel code or StartOfWeek enumeration that determines which day the week begins.

ISOWeekNum(DateTime)

  • DateTime - Required. Date/Time value to operate on. The week always begins on Monday.
Anonymous
Not applicable

Anyone managed to get the ISO week number working?

Would love to see an example.

Anonymous
Not applicable

Hi Oliver, have you managed? Using the example in the link I get "the expression is invalid"...

Anonymous
Not applicable

Here's how I managed to get ISO weeks

 

The 3 functions:

subtractFromTime(utcNow(), if(equals(dayofweek(utcNow()),0),6,sub(dayofweek(utcNow()),1)), 'Day')
 
addDays(outputs('Set_the_Monday'),3)
 
div(add(dayofyear(outputs('Thursday')),6),7)

 

 

 

angeloeef_0-1635434116151.png

 

grluquec
New Member

Hi all,

 

I have the same problem in Power Automate flow to get the Week Number of Year, so this is my solution:

 

1. Get the year of current date:

varYear = utcNow('yyyy')

    

2. Get the Day of Week for the first day of the current year. For example Jan 01-2021 was Friday or 5 day of week (0-6 week count):

varFWD = dayOfWeek(concat(variables('varYear'),'-01-01'))

 

3.  Get the Day of Year for current date. For example, for Nov 25-2021 is 329 day (1-365):

varDY = dayOfYear(utcNow())
 

4.  Get the Day of Week for current date. For example, for Nov 25-2021 is Thursday or 4:

varDW =dayOfWeek(utcNow())
 
5. Apply the follow formula to get the Week Number of Year:
varWeekNum = ((varDY - varDW + varFDW - 1) / 7 )+ 1
For example for Nov 25, 2021 is varWeekNum ((329 - 4 + 5 - 1) / 7 ) + 1 = 48
 
In code is:
varWeekNum = add(div(add(add(add(variables('varDY'), mul(variables('varDW'), -1)),variables('varFWD')), -1),7),1)
 
 
Note: you can convert utcNow to your local zone time to avoid any problem with time differences.
 
I hope this works for you and best luck to all.

This was perfect and much simpler than the other solutions.

 

I have a table in an excel file in a Sharepoint site.

The first column in the table is the Week Number

Column 2 I have calculate the month from the week number. (For anyone who may find this useful)

=TEXT((MONTH(DATE(YEAR(2021),1,1)+$A2*7-1)*29),"MMMM")

 

Now I will use the calculation of the ISO week to update a row on a Google Sheet. Power Automate only lets us do 1 row at a time, so this make it update the row designated for the current week.

greshnak
New Member

add(div(add(dayOfYear(variables('dateToday')),sub(dayOfWeek(concat('1/01/',formatDateTime(variables('dateToday'),'yyyy'))),1)),7),1)

Or replace the variable dateToday for utcNow()

Thank you for the formula ! 🙂

Hi so I am trying to calculate the number of weeks in a month using power automate, can you please assist me if you can

Pstork1
Most Valuable Professional
Most Valuable Professional

Please post this as a new question.  It will get more notice that way and others will be able to find the answer easier in the future.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,670)