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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SRJPBI
Frequent Visitor

How to calculate week number based on changing start dates?

Hi all,

 

I have a table within my Power BI report which looks a bit like this:

 

SRJPBI_0-1711034320809.png


A new row is added daily, with the date column defined as the current day. That said, I would like the solution to work even if the data load for some days fails, just in case.

 

There are never two offers active at the same time.

Offers can start in one year and finish in another.

Offers can begin and end on any day of the week.

Offers are not necessarily active for the same length of time.

 

I want to add a column flagging what week an offer is in on each date. However, the weeks should be defined as Sunday to Saturday. So the desired result would look like this:

 

SRJPBI_1-1711034347145.png

 

On 31/12/23 offer_week becomes 2 because that day is a Sunday, even though the offer is only on its second day. On 05/01/24 offer_week becomes 1 again because it is the first day of a new offer.

 

Does anyone know how to do this please?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SRJPBI 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1711075359454.png

 

Create a column. First check the date to see what day of the week it is. Determine if it's the first day of a new offer or if it's a Saturday.

 

offer_week = 
var min_date = 
    CALCULATE(
        MIN('Table'[date]), 
        FILTER(
            'Table', 
            'Table'[offer] = EARLIER('Table'[offer])
        )
    )
RETURN 
    IF(
        'Table'[date] = min_date 
        || 
        WEEKDAY('Table'[date], 2) = 6, 
        1, 
        2
    )

 

Here is the result.

 

vnuocmsft_1-1711075791379.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @SRJPBI 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1711075359454.png

 

Create a column. First check the date to see what day of the week it is. Determine if it's the first day of a new offer or if it's a Saturday.

 

offer_week = 
var min_date = 
    CALCULATE(
        MIN('Table'[date]), 
        FILTER(
            'Table', 
            'Table'[offer] = EARLIER('Table'[offer])
        )
    )
RETURN 
    IF(
        'Table'[date] = min_date 
        || 
        WEEKDAY('Table'[date], 2) = 6, 
        1, 
        2
    )

 

Here is the result.

 

vnuocmsft_1-1711075791379.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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