从 Power BI 中的日期字段获取 "Week of 2nd"
Get "Week of 2nd" from Date field in power BI
我的 DimDate 中有一个日期字段 table。
我想获得另一列 WeekOf
以显示基于星期一的周数。
例如我有日期:
Date WeekOf
10/2/2017 Week of 2nd
10/9/2017 Week of 9th
10/16/2017 Week of 16th
使用以下公式创建一个新列应该可以满足您的需求。
如果您想将其更改为不同日期的星期,请将 TargetDate 变量中的 2
更改为您想要的一周中的任何一天。
WeekOf =
VAR TargetDate = DAY(DATEADD(Dates[Date], 2 - WEEKDAY(Dates[Date]), DAY))
VAR TargetDateText = CONCATENATE(TargetDate, SWITCH(TargetDate, 1, "st", 21, "st", 31, "st", 2, "nd", 22, "nd", 3, "rd", 23, "rd", "th"))
RETURN
CONCATENATE("Week of ", TargetDateText)
我的 DimDate 中有一个日期字段 table。
我想获得另一列 WeekOf
以显示基于星期一的周数。
例如我有日期:
Date WeekOf
10/2/2017 Week of 2nd
10/9/2017 Week of 9th
10/16/2017 Week of 16th
使用以下公式创建一个新列应该可以满足您的需求。
如果您想将其更改为不同日期的星期,请将 TargetDate 变量中的 2
更改为您想要的一周中的任何一天。
WeekOf =
VAR TargetDate = DAY(DATEADD(Dates[Date], 2 - WEEKDAY(Dates[Date]), DAY))
VAR TargetDateText = CONCATENATE(TargetDate, SWITCH(TargetDate, 1, "st", 21, "st", 31, "st", 2, "nd", 22, "nd", 3, "rd", 23, "rd", "th"))
RETURN
CONCATENATE("Week of ", TargetDateText)