How do I calculate the average of the past 3 sales of an item?
Answers
-
Hi @meekey
you’ll want to use a lag function to get the last three values. Typically I use this when doing a rolling average like you’re needing. I’ve done a write up on rolling average and lag functions here: https://dojo.domo.com/main/discussion/52679/domo-ideas-conference-beast-modes-rolling-averages
window functions require your CSM to enable them in your instance to use
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I see so many examples of lag functions that all reference a date, so since I don't care about date necessarily, do I just leave end it with over ()?
(lag((sale_price),1) over( ) +
lag((sale_price),2) over( ) +
lag((sale_price),3) over( ) +
)/3
0 -
...also, I don't see LAG in my list of available functions... Sorry for such basic questions, Grant. Thanks for your help :)
0 -
@meekey the OVER clause tells you what to partition by - in your case I'd assume you'd want to do it on your asset and then order by date descending so you could find the last 3 sales for each asset.
Something like: lag(
sale_price
OVERasset
ORDER BYsale_date
desc)I think you may have to reach out to your CSM to get the lag function enabled if it doesn't currently work in your instance.
2
Categories
- 10.5K All Categories
- 8 Connect
- 918 Connectors
- 250 Workbench
- 470 Transform
- 1.7K Magic ETL
- 69 SQL DataFlows
- 477 Datasets
- 193 Visualize
- 252 Beast Mode
- 2.1K Charting
- 11 Variables
- 17 Automate
- 354 APIs & Domo Developer
- 89 Apps
- 3 Workflows
- 20 Predict
- 5 Jupyter Workspaces
- 15 R & Python Tiles
- 247 Distribute
- 63 Domo Everywhere
- 243 Scheduled Reports
- 21 Manage
- 42 Governance & Security
- 174 Product Ideas
- 1.2K Ideas Exchange
- 12 Community Forums
- 27 Getting Started
- 14 Community Member Introductions
- 55 Community News
- 4.5K Archive