简体   繁体   中英

Group by 7 day period on DataStudio related to current date

I need to group dates by week, but relative to the current date, I can't use the "Yearweek" dimension because it always starts on Sunday/Monday and I need more flexibility.

I have come up with kind of a solution, like this:

WHEN Date = DATETIME_SUB(TODAY(), INTERVAL 3 DAY) THEN "Week 1"
WHEN Date = DATETIME_SUB(TODAY(), INTERVAL 4 DAY) THEN "Week 1"
WHEN Date = DATETIME_SUB(TODAY(), INTERVAL 5 DAY) THEN "Week 1"
(...)
WHEN Date = DATETIME_SUB(TODAY(), INTERVAL 31 DAY) THEN "Week 4"
END

You get the idea...

Is there a more "elegant" way to do this? What if I need 8 weeks? Do I really need to extend this to 56 days?

Edit: I added an editable Looker Studio whit this rule to show you, and the correspondent sheets .

This is what I get, this works absolutely fine, I was just wondering if there was a better way to do it.

按周分组的条形图

It was as easy as

when DATE_DIFF(TODAY(), Date) >= 3 and DATE_DIFF(TODAY(), Date) <= 9 then "Week 1"

and so on...

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