#PowerQuery – Calculate the ISO date from year and a week number

Just wanted to share a M function that I just created to calculate the date from a Year and a ISO week number.

The example data is the following

Now the function I created can be called with the Year and Week number as parameters to get the following result

The function has the following code and will return the date of the Monday of the week number.

(TheYear as number, TheWeek as number) as date =>
let
//test
//TheYear = 2018,
//TheWeek = 1,
//
offsetToISO = Date.AddDays(#date(TheYear,1,1),-4),
dayOfWeek = Date.DayOfWeek(offsetToISO),
offset = -dayOfWeek + (TheWeek * 7),
isoWeekDate = Date.AddDays(offsetToISO, offset)
in
isoWeekDate

Hope this can help you too.

Here is a link to an example pbix file – link

11 thoughts on “#PowerQuery – Calculate the ISO date from year and a week number

  1. Pingback: Calculating ISO Date with M – Curated SQL

      1. No, in ISO it is the 22nd – as week number 1 starts on the 4th (first week with 4 or more days of the new year in)

  2. Great really nedded this:), what code change should i do i i want the date to be on friday insted om monday each week?

Leave a comment