Forum Discussion
sylvianelissen
1 year agoRegular Visitor
How to create date from week and year colums in powerquery?
Hi, I have data with a weeknumber column and a year column. How can I add an extra column that gives me the date of the first day of that week? Attached a print screen of my data. Thanks ...
- 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"
Fowmy
Super User
1 year agosylvianelissen
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.
sylvianelissen
1 year agoRegular Visitor
Thanks...but it works! It was the number format!