简体   繁体   中英

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. 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. You will have to construct your own date with the known year value and replace '30' with the known week value from your table

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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