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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
bmk
Helper II
Helper II

Return Max Week number based on number of days

Below image is two columns from a Date table, it shows Week number and Date.

 

How do I return the max week number for the last period with 7 days?

For example, the week number that should be returned from the below scenario is week 34.

bmk_0-1661977058425.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

First of all, thank you for your message via Linkedin.

I justed checked the message, and please check the below measure and the attached pbix file.

I tried to create a sample pbix file like below, and I hope the below can provide some ideas on how to create a solution for your dataset.

 

Expected result measure: =
VAR _weektable =
    FILTER (
        ADDCOLUMNS (
            VALUES ( Data[Week of Year] ),
            "@dayscountinaweek", CALCULATE ( COUNTROWS ( Data ) )
        ),
        [@dayscountinaweek] = 7
    )
RETURN
    MAXX ( _weektable, Data[Week of Year] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

First of all, thank you for your message via Linkedin.

I justed checked the message, and please check the below measure and the attached pbix file.

I tried to create a sample pbix file like below, and I hope the below can provide some ideas on how to create a solution for your dataset.

 

Expected result measure: =
VAR _weektable =
    FILTER (
        ADDCOLUMNS (
            VALUES ( Data[Week of Year] ),
            "@dayscountinaweek", CALCULATE ( COUNTROWS ( Data ) )
        ),
        [@dayscountinaweek] = 7
    )
RETURN
    MAXX ( _weektable, Data[Week of Year] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
bmk
Helper II
Helper II

The measure did not work. Also, noticed that when I use the measure, it filters the date range to the last 8 days (example, when a relative date of last 14 days is selected) only.

 

Measure : 

Measure = MAXX(FILTER('Date Table', 'Date Table'[Date] >= TODAY()-7 && 'Date Table'[Date] <= TODAY()), 'Date Table'[WeekNum])

As per image below, measure should still return 34. Since week 35 only has four days complete so far.

bmk_0-1662036825986.png

 

Anonymous
Not applicable

Hi @bmk ,

According to your description, You want to get the maximum Weeknum for the full week .Right?

(1)This is my test data:

yingyinr_0-1662344740621.png

 

(2)We can create a measure,then it can meet your need: Max_Weeknum

Max_Weeknum = MAXX( FILTER('Test', WEEKDAY('Test'[Date],2)=7 ) , 'Test'[Weeknum])

 

(3)The result is as follows:

yingyinr_1-1662344740622.png

If this method does not meet your needs, you can provide us your sample data without sensitive data, or detailed input and output sample data, so that we can better help for you.

 

Best Regards

amitchandak
Super User
Super User

@bmk ,  Try a measure like

Maxx(filter(Table, Table[Date] >= Today() -7  && Table[Date]  <= today()) , [Week])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.