简体   繁体   中英

How do I create a week to date Tableau calculation with a Monday week start

I'm working on a project where I must display several weeks of Sales, week to day. So, if today was Wednesday, all weeks displayed would show Monday, Tuesday and Wednesday. Weeks start on Monday and go to Sunday. I changed the week start in my data source settings but that did not fix my issue.

My original formula is as follows:

IF Datepart('weekday', [Date])<=DATEPART('weekday', TODAY()) THEN [Revenue] END This formula is close to what I need, but it unfortunately includes Sunday. I think this is because datepart numbers are fixed.

How can I modify this formula to show the days of the week based on a Monday start?

This formula works, but only shows me a single week (user should be able to select the last x number to weeks). IF DATEDIFF('week', DATETRUNC('week'[Date],'monday'),DATETRUNC('week',TODAY(),'monday'))=0 THEN [Sales] END

You could just tell it ignore Sunday (day 1). (Edit based on comments - if today is day 1 then show all). Modifying your calc:

IF DATEPART('weekday', TODAY()) = 1 THEN [Revenue] ELSEIF Datepart('weekday', [Date])>1 AND Datepart('weekday', [Date])<=DATEPART('weekday', TODAY()) THEN [Revenue] END

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