Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext 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
Good afternoon,
would like to return a target column that shows the Month which has higher working weeks in the selected week
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
Solved! Go to Solution.
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.
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.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 1 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 11 | |
| 6 | |
| 5 |