cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
micjensen
Frequent Visitor

Power Query Calendar Creation - 53 weeks

Hi Community

I really need your help on how to create a calendar that automatically knows that when it comes to the beginning of 2021, this is still week 53 and not week 1. I have only managed to create a calendar where the week number starts by 1 when entering a new calendar year. But for year 2021: the 1st to the 3rd january is week 53 and then week 1 starting from january 4th.

@PowerQuery @calendar@weeknum
How do i build in this knowledge ??

I rellay hope that someone has the answer to this, t

3 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @micjensen ,

This is very complex logic to code into Power Query.

I would recommend using WEEKNUM([Date], 21) in a DAX calculated column to be honest:

BA_Pete_0-1636123917354.png

BA_Pete_1-1636124036783.png

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

mahoneypat
Microsoft
Microsoft

Please see this article with a good way to handle that.

445 Calendar with 53-Week Years – Hoosier BI

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

ronrsnfld
Resident Rockstar
Resident Rockstar

Here's a custom function in M code for calculating the ISO Weeknumber (if that is what you want):

 

 

//fxISOWeekNum

(theDate as date) =>
let
   a = Date.AddDays(theDate,-1),
   b = Date.DayOfWeek(a,Day.Sunday),
   c = Date.AddDays(theDate,-b + 3),
   d2 = #date(Date.Year(c),1,3),
   IWN  =  Number.IntegerDivide(Number.From(theDate)-Number.From(d2) + Date.DayOfWeek(d2)+6,7)

in
    IWN

 

View solution in original post

4 REPLIES 4
DenisSipchenko
Advocate III
Advocate III

Please look Function for ISO Year/Week number (ISO 8601)) 


NB! Pay attention to offsetindays parameter (by default it equals to zero - it means week starts on Sunday)

ronrsnfld
Resident Rockstar
Resident Rockstar

Here's a custom function in M code for calculating the ISO Weeknumber (if that is what you want):

 

 

//fxISOWeekNum

(theDate as date) =>
let
   a = Date.AddDays(theDate,-1),
   b = Date.DayOfWeek(a,Day.Sunday),
   c = Date.AddDays(theDate,-b + 3),
   d2 = #date(Date.Year(c),1,3),
   IWN  =  Number.IntegerDivide(Number.From(theDate)-Number.From(d2) + Date.DayOfWeek(d2)+6,7)

in
    IWN

 

mahoneypat
Microsoft
Microsoft

Please see this article with a good way to handle that.

445 Calendar with 53-Week Years – Hoosier BI

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


BA_Pete
Super User
Super User

Hi @micjensen ,

This is very complex logic to code into Power Query.

I would recommend using WEEKNUM([Date], 21) in a DAX calculated column to be honest:

BA_Pete_0-1636123917354.png

BA_Pete_1-1636124036783.png

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors