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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Calculated Column Time Intelligence

Good afternoon,
would like to return a target column that shows the Month which has higher working weeks in the selected week

marcoproserpio_0-1688744028794.png

For example target return shall be March for week 15 as of having 5 to 0 in comparing (march - april).

Thanks

W_Days IN week = 
 
var x = CALCULATE(count('Calendar'[Month]), ALLEXCEPT('Calendar','Calendar'[Weeknum],'Calendar'[Month]),WEEKDAY('Calendar'[Date],2)<>7 && WEEKDAY('Calendar'[Date],2)<>6) 

var y = SWITCH(TRUE(),isblank(x)=TRUE(),0,x)
return 
y
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

 

Please have a try.

 

 

Working Weeks =
VAR CurrentWeek = [Week]
VAR CurrentMonth =
    MONTH ( [Date] )
VAR NextMonth =
    MONTH ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ) + 1, 1 ) )
VAR DaysInCurrentMonth =
    DAY ( EOMONTH ( [Date], 0 ) )
VAR DaysInNextMonth =
    DAY ( EOMONTH ( [Date], 1 ) )
VAR CurrentWeekDays =
    SWITCH ( CurrentWeek, 1, 7, 2, 6, 3, 5, 4, 4, 5, 3, 6, 2, 7, 1 )
VAR NextMonthDays = 7 - CurrentWeekDays
VAR CurrentMonthWorkingDays = DaysInCurrentMonth - CurrentWeekDays
VAR NextMonthWorkingDays = DaysInNextMonth - NextMonthDays
VAR WorkingWeeks =
    IF ( CurrentMonthWorkingDays >= 5, 5, CurrentMonthWorkingDays ) / 5
        + IF ( NextMonthWorkingDays >= 5, 5, NextMonthWorkingDays ) / 5
RETURN
    WorkingWeeks

 

 

Then create another column.

 

 

Target Month =
VAR CurrentMonth =
    MONTH ( [Date] )
VAR NextMonth =
    MONTH ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ) + 1, 1 ) )
VAR CurrentMonthWorkingWeeks = [Working Weeks]
VAR NextMonthWorkingWeeks =
    CALCULATE (
        SUM ( [Working Weeks] ),
        DATESBETWEEN (
            'Table'[Date],
            DATE ( YEAR ( 'Table'[Date] ), NextMonth, 1 ),
            DATE ( YEAR ( 'Table'[Date] ), NextMonth, 7 )
        )
    )
RETURN
    IF (
        CurrentMonthWorkingWeeks >= NextMonthWorkingWeeks,
        CurrentMonth,
        NextMonth
    )

 

 

Add the "Target Month" calculated column to your visualizations to see the month with the highest number of working weeks for each week.

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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 @Anonymous 

 

Please have a try.

 

 

Working Weeks =
VAR CurrentWeek = [Week]
VAR CurrentMonth =
    MONTH ( [Date] )
VAR NextMonth =
    MONTH ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ) + 1, 1 ) )
VAR DaysInCurrentMonth =
    DAY ( EOMONTH ( [Date], 0 ) )
VAR DaysInNextMonth =
    DAY ( EOMONTH ( [Date], 1 ) )
VAR CurrentWeekDays =
    SWITCH ( CurrentWeek, 1, 7, 2, 6, 3, 5, 4, 4, 5, 3, 6, 2, 7, 1 )
VAR NextMonthDays = 7 - CurrentWeekDays
VAR CurrentMonthWorkingDays = DaysInCurrentMonth - CurrentWeekDays
VAR NextMonthWorkingDays = DaysInNextMonth - NextMonthDays
VAR WorkingWeeks =
    IF ( CurrentMonthWorkingDays >= 5, 5, CurrentMonthWorkingDays ) / 5
        + IF ( NextMonthWorkingDays >= 5, 5, NextMonthWorkingDays ) / 5
RETURN
    WorkingWeeks

 

 

Then create another column.

 

 

Target Month =
VAR CurrentMonth =
    MONTH ( [Date] )
VAR NextMonth =
    MONTH ( DATE ( YEAR ( [Date] ), MONTH ( [Date] ) + 1, 1 ) )
VAR CurrentMonthWorkingWeeks = [Working Weeks]
VAR NextMonthWorkingWeeks =
    CALCULATE (
        SUM ( [Working Weeks] ),
        DATESBETWEEN (
            'Table'[Date],
            DATE ( YEAR ( 'Table'[Date] ), NextMonth, 1 ),
            DATE ( YEAR ( 'Table'[Date] ), NextMonth, 7 )
        )
    )
RETURN
    IF (
        CurrentMonthWorkingWeeks >= NextMonthWorkingWeeks,
        CurrentMonth,
        NextMonth
    )

 

 

Add the "Target Month" calculated column to your visualizations to see the month with the highest number of working weeks for each week.

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.