简体   繁体   English

Power BI-您如何计算每周的第一天?

[英]Power BI - How do you calculate first Day of Week?

So here is my scenario. 所以这是我的情况。 If it's 20th week of the Year 2016, I need to know it's 5/8/2016. 如果是2016年的第20周,我需要知道它是2016年5月8日。 This is consistent for the rest of week. 这与一周的其余时间保持一致。 Same goes for all the week. 整个星期都一样。

Week#   WeekDate
29     7/10/2016 0:00
30     7/17/2016 0:00
28     7/3/2016 0:00
31     7/24/2016 0:00
32     7/31/2016 0:00
33     8/7/2016 0:00
34     8/14/2016 0:00
dateadd(DAY,-(datepart(weekday,DATEADD(WEEK,30-1,CAST('2016'||'-1-1' AS DATE)))-1),DATEADD(WEEK,30-1,CAST('2016'||'-1-1' AS DATE)))

This works with Intersystems. 这适用于Intersystems。 You will have to construct your own date with the known year value and replace '30' with the known week value from your table 您将必须用已知的年值构造自己的日期,并用表中的已知的周值替换“ 30”

Thanks for the contribution, I did something like below and it worked. 感谢您的贡献,我做了以下类似的工作,并且成功了。 This is keeping Sunday as the first day of week. 这将星期日保持为一周的第一天。

If you want to use Monday or Tuesday, add +2, +3 in the WeekNum calculation below. 如果要使用星期一或星期二,请在下面的WeekNum计算中添加+ 2,+ 3。

DATE(SampleTableWithDate.Year],1,1) - WEEKDAY(DATE(SampleTableWithDate.Year,1,1),1)  + (WEEKNUM(SampleTableWithDate.Date)-1)*7 + 1

Find the First Date of this Year    -  First Day of Week This Year                   + Add Weeks till Date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM