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
Rigoleto
Helper II
Helper II

How to know the month of a week

Hi,

 

Is there a way to know the month of a week, for instance:

 

Week                Month

1                         Junuary

26                       Frebuary

 

I need to resolve the month in order to use it in a chart

 

Rigo

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Here is a surprisingly complex measure to do this:

 

Week Month = 
VAR __Year = 2018
VAR __Week = MAX(Weeks[Value])
VAR __Calendar = 
    ADDCOLUMNS(
        CALENDAR(DATE(__Year,1,1),DATE(__Year,12,31)),
        "__WeekNum",WEEKNUM([Date]),
        "__Month",MONTH([Date]),
        "__MonthName",FORMAT([Date],"mmmm")
    )
VAR __FilteredCalendar = FILTER(__Calendar,[__WeekNum]=__Week)
VAR __MaxMonth = MAXX(__FilteredCalendar,[__Month]) //switch to MINX for week start month instead of week end month
VAR __FilteredCalendar2 = FILTER(__FilteredCalendar,[__Month]=__MaxMonth)
RETURN MAXX(__FilteredCalendar2,[__MonthName])

You will have to decide what you want to do with weeks that span months. See the comment.

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @Rigoleto

 

You can also create a calendar table and get the week number of Month. Then link the calendar table with week table. You can get the Month with Related Function.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Here is a surprisingly complex measure to do this:

 

Week Month = 
VAR __Year = 2018
VAR __Week = MAX(Weeks[Value])
VAR __Calendar = 
    ADDCOLUMNS(
        CALENDAR(DATE(__Year,1,1),DATE(__Year,12,31)),
        "__WeekNum",WEEKNUM([Date]),
        "__Month",MONTH([Date]),
        "__MonthName",FORMAT([Date],"mmmm")
    )
VAR __FilteredCalendar = FILTER(__Calendar,[__WeekNum]=__Week)
VAR __MaxMonth = MAXX(__FilteredCalendar,[__Month]) //switch to MINX for week start month instead of week end month
VAR __FilteredCalendar2 = FILTER(__FilteredCalendar,[__Month]=__MaxMonth)
RETURN MAXX(__FilteredCalendar2,[__MonthName])

You will have to decide what you want to do with weeks that span months. See the comment.

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.