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.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 618 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 741 Beast Mode
- 58 App Studio
- 40 Variables
- 686 Automate
- 176 Apps
- 453 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 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