Converting Week numbers into date ranges
Best Answers
-
There are a few options that I have used in the past. I'll outline them below. The main strategy is to shift the date in each row of your data backwards (or forwards) and then extract the portion you want.
SUBDATE(`Date`,WEEKDAY(`Date`)-1)
This is the simplest version and returns the full date of the date's Sunday. This returns "2015-01-04" from your example (in 2015, the first and seventh of January fell in different weeks).
Note that even though this looks like a date, Domo will consider it a character value. The upshot is that you cannot use the date grain selector on this value, all cards using this Beast Mode will always be locked to weekly.
DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%m/%d/%Y')
Same as previous only we format the date so it looks like this: "01/04/2015".
CONCAT('Week beg: ',DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%b-%d'))
This version puts the text "Week beg:" and then only shows the month and day of that week's Sunday. Example: "Week beg: Jan 04".
CONCAT(DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%b %d'),' - ',DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-7),'%b %d %Y'))
This version gets closest to your example below. Note that the values will span both months and years. This version returns "Jan 01 - Jan 07 2015" for your example.
The year is always associated with the end of the week. For the last week of 2014, you would see "Dec 28 - Jan 03 2015".
You could get really fancy and do some conditional logic around whether the month at the beginning of the week matches the month at the end of the week (likewise for the year). For each case you would need something similar to the last example. That gets a little complex for my taste but it could certainly be done.
-----
I work for Domo.
**Say "Thanks" by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as "Accepted Solution"16 -
no you can't shift it with the out of the box functionality. You would have to load it in as part of your dataset or build a beast mode but you will lose the time grain functionality if you build a customer date field.
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'2
Answers
-
Are you starting with raw dates and the "week-1 2015" is generated by the domo card or does the raw data have a column with "week-1 2015" in it?
**Say “Thanks" by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
I am starting with raw dates that domo is transforming into "week-1 2015"
0 -
There are a few options that I have used in the past. I'll outline them below. The main strategy is to shift the date in each row of your data backwards (or forwards) and then extract the portion you want.
SUBDATE(`Date`,WEEKDAY(`Date`)-1)
This is the simplest version and returns the full date of the date's Sunday. This returns "2015-01-04" from your example (in 2015, the first and seventh of January fell in different weeks).
Note that even though this looks like a date, Domo will consider it a character value. The upshot is that you cannot use the date grain selector on this value, all cards using this Beast Mode will always be locked to weekly.
DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%m/%d/%Y')
Same as previous only we format the date so it looks like this: "01/04/2015".
CONCAT('Week beg: ',DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%b-%d'))
This version puts the text "Week beg:" and then only shows the month and day of that week's Sunday. Example: "Week beg: Jan 04".
CONCAT(DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-1),'%b %d'),' - ',DATE_FORMAT(SUBDATE(`Date`,WEEKDAY(`Date`)-7),'%b %d %Y'))
This version gets closest to your example below. Note that the values will span both months and years. This version returns "Jan 01 - Jan 07 2015" for your example.
The year is always associated with the end of the week. For the last week of 2014, you would see "Dec 28 - Jan 03 2015".
You could get really fancy and do some conditional logic around whether the month at the beginning of the week matches the month at the end of the week (likewise for the year). For each case you would need something similar to the last example. That gets a little complex for my taste but it could certainly be done.
-----
I work for Domo.
**Say "Thanks" by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as "Accepted Solution"16 -
Is it possible to shift this around to start on a different day of the week other than Sunday? In other words, look at Friday-Thursday instead of Sunday-Saturday.
0 -
Hi all,
Does anybody have any input for @CantStopTheHopp with their follow-up question? If you can't find an answer here, feel free to open a new topic with your question!
0 -
no you can't shift it with the out of the box functionality. You would have to load it in as part of your dataset or build a beast mode but you will lose the time grain functionality if you build a customer date field.
Domo Arigato!
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'2 -
@CantStopTheHopp, did Godzilla's response help address your follow-up question?
0 -
Yes that is what I was thinking but was wanting to confirm. Fortunately it wasn't a crucial need so I'm not going to bother looking into it further.
1 -
good stuff! Thank you!
0 -
This solution doesn't work when comparing Y-o-Y data
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 737 Beast Mode
- 56 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive