根据月和年列计算工作日数-DAX

问题描述 投票:0回答:1

我在下面的一列中希望提取工作日数(不包括周末,周六和周日,节假日无需处理)。

到目前为止,我只想要:

Required_Column = Total No of Days in that month - No of weekends in that month

Month_Year
01-2018
02-2018
03-2018
...
...
01-2019
02-2019

我是Power查询和DAX的新手,我尝试使用DAX查找各种方法,但是找不到任何相关的线索。

预期输出:

Month_Year   Required_Column
01-2018      23 (31-8)
02-2018      20 (28-8)
03-2018      22 (31-9)
...          ...
...          ...
01-2019      23 (31-8)
02-2019      20 (28-8)

感谢您的帮助。

powerbi dax powerquery
1个回答
0
投票

尽管建议使用基于日历表的方法,如RADO和Strawberryshrub的评论所述,但也可以使用DAX计算列进行此操作。

在下面的示例中,我假设MonthYear列包含每个月的第一天。

WorkingDays = 
VAR Year = YEAR( [MonthYear] )
VAR Month = MONTH( [MonthYear] )
VAR DatesInMonth = GENERATESERIES( [MonthYear], DATE( Year, Month + 1, 1 ) - 1, 1 )
RETURN SUMX(
    DatesInMonth,
    IF( WEEKDAY( [Value] ) IN { 1, 7 }, 0, 1 )
)

Result

© www.soinside.com 2019 - 2024. All rights reserved.