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 September 15. Request your voucher.

Reply
mb0307
Responsive Resident
Responsive Resident

Weeks into Month by Number of Days

Hi,

 

In my Date table, I want to convert weeks into monthly buckets by using this logic: 

If a week falls between two months, I will assign that week to the month with the most number of days for that week. 

 

Week Format:  WEEK/YEAR  (03/2024)

 

Example below,

  • Week 5 should be assigned to Feb 2024 (4 days in Feb)
  • Week 9 should be assigned to Feb 2024 ( 4 days in Feb)

mb0307_0-1701458370906.png

 

How can I achieve this in Calculated Column in Date Table please?

 

Thanks 

1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@mb0307 Maybe:

Week = 
    VAR __Date = [Date]
    VAR __Year = YEAR([Date])
    VAR __Week = WEEKNUM( __Date, 2 )
    VAR __Month = MONTH( __Date )
    VAR __Table = 
        ADDCOLUMNS(
            FILTER( 'Dates', WEEKNUM( [Date] ) = __Week ),
            "__Month", MONTH( [Date] )
        )
    VAR __Min = MINX( __Table, [__Month] )
    VAR __DaysInMonth = COUNTROWS( FILTER( __Table, [__Month] = __Month ) )
    VAR __Result = 
        SWITCH( TRUE(),
            __DaysInMonth > 3, FORMAT( __Week, "00" ) & "/" & __Year,
            __Min = __Month, FORMAT( __Week + 1, "00") & "/" & __Year,
            FORMAT( __Week - 1, "00" ) & "/" & __Year
        )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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