如何为每个月的第一个工作日创建标志
how to create flag for first working day of each month
由于我对 Power BI 和 DAX 还很陌生,因此找不到解决当前问题的方法。非常感谢您的帮助!!
我已经有约会了table。它包含几年的日期以及每周第一个工作日的标志(因此可以排除周末和节假日)。但是我需要一面旗帜来标记每个月的第一个工作日。我稍后会将该标志用于另一个 table 中的某些条目,专门用于该事实 table.
中包含的所有月份的第一个工作日。
我有:
date
month
year
first_workday_per_week
01Jan2010
01
2010
0
02Jan2010
01
2010
0
03Jan2010
01
2010
0
04Jan2010
01
2010
1
05Jan2010
01
2010
0
06Jan2010
01
2010
0
...
11Jan2010
01
2010
1
...
01FEB2010
02
2010
1
我现在每周都有第一个工作日,但每个月都需要。喜欢...
date
month
year
first_workday_per_week
first_workday_per_month
01Jan2010
01
2010
0
0
02Jan2010
01
2010
0
0
03Jan2010
01
2010
0
0
04Jan2010
01
2010
1
1
05Jan2010
01
2010
0
0
06Jan2010
01
2010
0
0
...
11Jan2010
01
2010
1
0
...
01FEB2010
02
2010
1
1
我尝试在我的日期中创建一个新列 table 以查看是否可以找到每个月第一个工作日的正确日期:
first_workday_per_month = CALCULATE(min(D_DATE[Date]), D_DATE[first_workday_per_week ]=1, month(D_DATE[Date]) = D_DATE[month])
但是,这只给我每年的第一个工作日。
所以我需要一些帮助来找到每个月的第一个工作日,如果可能的话,还有创建标志的方法。
创建标志我将执行以下操作:
flag_workday_p_month = If(Calculate( First part of Question ) = DATE[date],1,0)
非常感谢您的帮助!谢谢!
韩国,
马丁
如果年份和月份与使用 EARLIER
的当前行匹配,则使用 CALCULATE
过滤您的日期 table。然后过滤如果first_workday_per_week = 1
。取这些匹配值的 MIN
来获取日期,然后将其与 IF
语句与当前行中的日期进行比较。
first_workday_per_month =
IF( CALCULATE( MIN ('D_DATE'[date]),
FILTER ('D_DATE', 'D_DATE'[year] = EARLIER('D_DATE'[year]) ),
FILTER ('D_DATE', 'D_DATE'[month] = EARLIER('D_DATE'[month]) ),
'D_DATE'[first_workday_per_week] = 1 ) = 'D_DATE'[date],
1, 0)
由于我对 Power BI 和 DAX 还很陌生,因此找不到解决当前问题的方法。非常感谢您的帮助!!
我已经有约会了table。它包含几年的日期以及每周第一个工作日的标志(因此可以排除周末和节假日)。但是我需要一面旗帜来标记每个月的第一个工作日。我稍后会将该标志用于另一个 table 中的某些条目,专门用于该事实 table.
中包含的所有月份的第一个工作日。我有:
date | month | year | first_workday_per_week |
---|---|---|---|
01Jan2010 | 01 | 2010 | 0 |
02Jan2010 | 01 | 2010 | 0 |
03Jan2010 | 01 | 2010 | 0 |
04Jan2010 | 01 | 2010 | 1 |
05Jan2010 | 01 | 2010 | 0 |
06Jan2010 | 01 | 2010 | 0 |
... | |||
11Jan2010 | 01 | 2010 | 1 |
... | |||
01FEB2010 | 02 | 2010 | 1 |
我现在每周都有第一个工作日,但每个月都需要。喜欢...
date | month | year | first_workday_per_week | first_workday_per_month |
---|---|---|---|---|
01Jan2010 | 01 | 2010 | 0 | 0 |
02Jan2010 | 01 | 2010 | 0 | 0 |
03Jan2010 | 01 | 2010 | 0 | 0 |
04Jan2010 | 01 | 2010 | 1 | 1 |
05Jan2010 | 01 | 2010 | 0 | 0 |
06Jan2010 | 01 | 2010 | 0 | 0 |
... | ||||
11Jan2010 | 01 | 2010 | 1 | 0 |
... | ||||
01FEB2010 | 02 | 2010 | 1 | 1 |
我尝试在我的日期中创建一个新列 table 以查看是否可以找到每个月第一个工作日的正确日期:
first_workday_per_month = CALCULATE(min(D_DATE[Date]), D_DATE[first_workday_per_week ]=1, month(D_DATE[Date]) = D_DATE[month])
但是,这只给我每年的第一个工作日。 所以我需要一些帮助来找到每个月的第一个工作日,如果可能的话,还有创建标志的方法。
创建标志我将执行以下操作:
flag_workday_p_month = If(Calculate( First part of Question ) = DATE[date],1,0)
非常感谢您的帮助!谢谢!
韩国, 马丁
如果年份和月份与使用 EARLIER
的当前行匹配,则使用 CALCULATE
过滤您的日期 table。然后过滤如果first_workday_per_week = 1
。取这些匹配值的 MIN
来获取日期,然后将其与 IF
语句与当前行中的日期进行比较。
first_workday_per_month =
IF( CALCULATE( MIN ('D_DATE'[date]),
FILTER ('D_DATE', 'D_DATE'[year] = EARLIER('D_DATE'[year]) ),
FILTER ('D_DATE', 'D_DATE'[month] = EARLIER('D_DATE'[month]) ),
'D_DATE'[first_workday_per_week] = 1 ) = 'D_DATE'[date],
1, 0)