Forum Discussion
How to create date from week and year colums in powerquery?
- 1 year ago
Hi sylvianelissen,
I realise Fowmy just replied, but just adding an option I had been looking at.
If you are using ISO Weeks, you would need to implement something like this:
In Power Query, you could create a function to do the conversion:
//fn_YearWeeknumToWeekStartDate (Year as number, #"Week Number" as number) as date => let Jan01 = #date(Year, 1, 1), Jan03 = #date(Year, 1, 3), Jan03_DayOfWeek = Date.DayOfWeek(Jan03, Day.Sunday), WeekStartDate = Date.AddDays(Jan01, - Jan03_DayOfWeek + #"Week Number" * 7 - 4) in WeekStartDateBelow is a sample query to test the above function:
let Source = #table( type table [Jaar = Int64.Type, Weeknummer = Int64.Type], {{2025, 1}, {2025, 2}, {2025, 3}, {2025, 4}} ), #"Added Week Start Date" = Table.AddColumn( Source, "Week Start Date", each fn_YearWeeknumToWeekStartDate([Jaar], [Weeknummer]), type date ) in #"Added Week Start Date"
sylvianelissen
Add a custom column: I assumed week starts on Monday. you may change it if it's different
Date.StartOfWeek(Date.AddWeeks(#date([Jaar], 1, 1), [Weeknummer] - 1), Day.Monday)
Thanks for your reply, but your code gives an error....any suggestions? See print screen
- Fowmy1 year ago
Super User
sylvianelissen
Sorry, I can't see the exact error message from here. Could you verify that the year and week number are correct and thier data types are numbers? Click on any cell showing "Error," check the detailed error message below, and share a screenshot to help diagnose the issue.- sylvianelissen1 year agoRegular Visitor
Thanks...but it works! It was the number format!