Beast Mode Formula for Previous Complete Weeks
I need to display results in cards from the last complete weeks in a dataset.
(This dataset is on a 7-day lag. Thus making it not compatible with the Period over Period cards. Which is cray cray to me. There should be an option to align to the data set rather than today's actual date... I mean... lots to love about Domo. But some basic visualization platforms can do this... annnnnnyway)
Here are the date range groups I will need:
Note: Last complete weeks are Sun-Sat
- Last Complete Week
- -1 Week from Last Complete Week Total
- Prior 3-Week Rolling Average from Last Complete Week
- Prior 6-Week Rolling Average from Last Complete Week
- Prior 12-Week Rolling Average from Last Complete Week
Ex: "Prior 3-Week Rolling Average from Last Complete Week" means -1,-2,-3 weeks back from the Last Complete Week
Each of those totals will then be compared to the Last Complete Week to show the rate of change like the example below.
Question:
- What Beast Mode formula can be used to filter data to the Last Complete Week and the subsequent data range groups I listed above?
Comments
-
@RocketMichael to get the date of the last complete week, you can use this formula:
DATE_ADD(`dt`, INTERVAL (7- DAYOFWEEK(`dt`)) DAY)
to get the rolling averages, I will refer you to this post that goes over it.
You would inject your last complete week formula into this.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
@MarkSnodgrass Thanks for the link!
So, would the 3-week rolling average prior to the last complete week look like this?
(LAG(SUM(DATE_ADD(`dt`, INTERVAL (7- DAYOFWEEK(`dt`)) DAY)), 3) OVER (ORDER BY `dt`) + LAG(SUM(DATE_ADD(`dt`, INTERVAL (7- DAYOFWEEK(`dt`)) DAY)), 2) OVER (ORDER BY `dt`) + LAG(SUM(DATE_ADD(`dt`, INTERVAL (7- DAYOFWEEK(`dt`)) DAY)), 1) OVER (ORDER BY `dt`)) / 3
0 -
No, your sum would be your sales amount column, not the date calculation. What does your data look like? Do you have one entry per day? One entry per week? That will make a difference in the lag.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
@MarkSnodgrass Oops. Misunderstood there.
The data contains singular daily entries. It's always 7 days behind today's date in terms of data availability.
0 -
@MarkSnodgrass and @RocketMichael the risk with LAG() is that if you have a gap in your data (i.e. sales on 6 out of 7 days) that would throw off LAG because LAG 7 would actually be the 8th day back.
instead you might consider trying to use Variables (beta feature maybe GA check with your CSM) to address the problem.
basically you define a variable report_date which you can then alter for all of your calcs
avg_rolling_14 = sum(case when trans_date >= date_add(report_date interval -14 days) and trans_date < report_date then amount end) / count(case when trans_date >= date_add(report_date interval -14 days) and trans_date < report_date then report_date end)
in this example report_date is user define-able and you're calculating total sales within 14 days divided by the number of days of sales within 14 days.
Only hitch in the plan is that Domo does not support Dates as variables so you have to use current_date - date_offset as a surrogate for report date.
in other words your variable is date_offset and replace all instances of "report_date" above with...
date_add(today(), interval - date_offset days)
this is pseudo code so test it, but it should work with a little tweaking :D
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"2
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive