Forum Discussion
WeekNum out by a few
- 10 years ago
It looks like Power BI counts the first week of the year starting on 1/1/2016, rather than including it in part of the last week of the prior year.
That goes against many standard calendars, specifically the ISO definition.
I'm not sure why MS uses a different system, but knowing when they start, you could subtract one from your formula and get the result you wanted.
This is also the default behavior in Excel, unless you use =WEEKNUM(DateCell, 21). In Power BI, there is no option for this. You can vote on the idea here to make that happen.
EDIT: other posters mentioned after this was accepted as a solution that you can use WEEKNUM([DateColumn], 21) in Power BI, it's just not documented and doesn't show up as a standard option while writing the formula. Thanks for pointing this out!
You need to realize that there are many different ways of measuring the week num of the year. ISO, standard calendar, 1st full week starting on Sat, Sun or Mon, or different Fiscal calendars starting at other times throughout the year. I personally think the ISO standard is the easiest to deal with, and in excel can be used either with =WEEKNUM([Date],21) or =ISOWEEK([Date]).
In PowerBI, There are two ways to get the ISO Week:
- Using a DAX query: (it's a nice undocumented option that still works the same as Excel.)
ISO Week = WEEKNUM([Date],21)
- Using M in the Query Editor:
ISO Week = Number.RoundDown((Date.DayOfYear(Date.From(Duration.Days(([Date]-Date.From(2))/7)*7+5))+6)/7)