Get “Week of 2nd” from Date field in power BI

北城以北 提交于 2019-12-25 11:56:23

问题


I have a date field in my DimDate table.

I want to get another column WeekOf that would show the week number based on Monday. For example I have date:

  Date         WeekOf
10/2/2017   Week of 2nd
10/9/2017   Week of 9th
10/16/2017  Week of 16th

回答1:


Creating a new column with the following formula should give you what you want.

If you every want to change it to be the Week of a different day, change the 2 in the TargetDate variable to which ever day of the week you want.

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)



来源:https://stackoverflow.com/questions/46715524/get-week-of-2nd-from-date-field-in-power-bi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!