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
Pingback: Calculating ISO Date with M – Curated SQL
thanks!
I tried it but I am not understanding how year 2019 week 1 could have date of 12/31/2018
2021, 8 should be Feb 15th(Considering Monday as the first day of the week) but I am getting 02/22/2021
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)
Hi Harsh –
week 1 2019 (ISO) begins on the 12/31/2018 🙂
https://en.wikipedia.org/wiki/ISO_week_date
Great really nedded this:), what code change should i do i i want the date to be on friday insted om monday each week?
Hi Joakim – you can add 4 days to the monday date – ie offset + 4
Its giving Sunday as the first day of the week
What is your regional settings in Power BI desktop and the PC ?
This Function helps me a lot. Thank You!!