Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
FireFighter1017
Advocate II
Advocate II

Relative date filter Last 52 Calendar Weeks gives me 53 weeks

Hi,

I've been experimenting the relative date filters lately.

Especially selecting Last x calendar weeks.

 

Then I came upon some strange results which I don't understand completely.

So I have this Date Table where I have created a column [Week#] that gives me the week number from this formula:

 

YEAR([Date])&"-W"&WEEKNUM([Date])

 

I used an ISO notation so I don't have to make any calculations to have it sequenced properly over years.

I don't have the script for the date table.  But let's say it has columns [Date] and [Week#].

 

Then I filter this table using [Date] field using a Realtive Date filter like this one: "Last 52 Calendar weeks".

Then I put a card visual showing the distinct count of [Week#].

And now it shows me 53.  (wtf???)

 

I extracted this table showing you the start and end of each weeks and the week#:

KPI Week #Week StartWeek End
2019-W4611/10/201911/16/2019
2019-W4711/17/201911/23/2019
2019-W4811/24/201911/30/2019
2019-W4912/1/201912/7/2019
2019-W5012/8/201912/14/2019
2019-W5112/15/201912/21/2019
2019-W5212/22/201912/28/2019
2019-W5312/29/20191/4/2020
2020-W0112/29/20191/4/2020
2020-W021/5/20201/11/2020
2020-W031/12/20201/18/2020
2020-W041/19/20201/25/2020
2020-W051/26/20202/1/2020
2020-W062/2/20202/8/2020
2020-W072/9/20202/15/2020
2020-W082/16/20202/22/2020
2020-W092/23/20202/29/2020
2020-W103/1/20203/7/2020
2020-W113/8/20203/14/2020
2020-W123/15/20203/21/2020
2020-W133/22/20203/28/2020
2020-W143/29/20204/4/2020
2020-W154/5/20204/11/2020
2020-W164/12/20204/18/2020
2020-W174/19/20204/25/2020
2020-W184/26/20205/2/2020
2020-W195/3/20205/9/2020
2020-W205/10/20205/16/2020
2020-W215/17/20205/23/2020
2020-W225/24/20205/30/2020
2020-W235/31/20206/6/2020
2020-W246/7/20206/13/2020
2020-W256/14/20206/20/2020
2020-W266/21/20206/27/2020
2020-W276/28/20207/4/2020
2020-W287/5/20207/11/2020
2020-W297/12/20207/18/2020
2020-W307/19/20207/25/2020
2020-W317/26/20208/1/2020
2020-W328/2/20208/8/2020
2020-W338/9/20208/15/2020
2020-W348/16/20208/22/2020
2020-W358/23/20208/29/2020
2020-W368/30/20209/5/2020
2020-W379/6/20209/12/2020
2020-W389/13/20209/19/2020
2020-W399/20/20209/26/2020
2020-W409/27/202010/3/2020
2020-W4110/4/202010/10/2020
2020-W4210/11/202010/17/2020
2020-W4310/18/202010/24/2020
2020-W4410/25/202010/31/2020
2020-W4511/1/202011/7/2020

 

From week 2019-W46 start date to 2020-W45 end date, it's 363 days, and 51.86 weeks.

 

I think I have found the reason why it is not calculating weeks properly.

Even though WEEKNUM formula seems to use ISO week numbering, it fails to implement correctly the week overlapping two years.

If you look at week 2019-W53, you'll notice that it only has 3 days and week 2020-W01 has 4 days.

 

Normally, week 2019-W53 would have been in fact Week 2020-W01 since it has a Thursday, as per ISO 8601.

But unfortunately, Power BI does not have a ISOWEEKNUM formula, and its WEEKNUM is not the same as the one in Excel.

Excel actually does have a 1st week of the year rule in its WEEKNUM formula.  Which in 2019 and 2020 gives same results as ISOWEEKNUM.  But once every 4 years, it is not inline with ISOWEEKNUM.

 

Power BI should have ISOWEEKNUM formula so we can apply proper ISO week numbers to our dates tables.

 

In the meantime, I'll be recreating the ISOWEEKNUM formula in Power BI in order to get 52 weeks when I ask for last 52 weeks.

So if anyone's already done this, please let me know.

Otherwise, I'll probably be posting my solution here.

 

 

1 ACCEPTED SOLUTION
FireFighter1017
Advocate II
Advocate II

I found a post referencing this :https://blog.gbrueckl.at/2012/04/iso-8601-week-in-dax/

Looks like Excel ISOWEEKNUM was in fact some version of WEEKNUM with undocumented parameters.

 

Now, is it ok to use back-doors like this?  I never was fond of it.

Please Microsoft, make an ISOWEEKNUM to make it official or at lest document the '21' constant used to get ISO week numbers.

View solution in original post

3 REPLIES 3
AnnaSundboel
New Member

hello there

 

I have the same issue. 

 

From your posts I understand that it hasn't been solved, has it?

 

br

Anna

Hello AnnaSundboel,

There is an undocumentated workaround using constant 21 for function WEEKNUM:

YEAR([Date])&"-W"&WEEKNUM([Date], 21)

I've tested it and it worked the same as ISOWEEKNUM in Excel. 

FireFighter1017
Advocate II
Advocate II

I found a post referencing this :https://blog.gbrueckl.at/2012/04/iso-8601-week-in-dax/

Looks like Excel ISOWEEKNUM was in fact some version of WEEKNUM with undocumented parameters.

 

Now, is it ok to use back-doors like this?  I never was fond of it.

Please Microsoft, make an ISOWEEKNUM to make it official or at lest document the '21' constant used to get ISO week numbers.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.