Need help to show total of last 18 months for each month for last 12 months
Hi Experts,
I need to display a chart for the total number of patients for the last 18 months for each month for the last 12 months. I need help in figuring out this visualization through beast mode since I do not where to start.
I am new to domo and beast modes and will appreciate you all helping me out here.
Thank you :)
Vy
Answers
-
Hi @user012068
What format is your data in? Is it already aggregated on a monthly basis or is it daily?
You'll want to make sure your data is aggregated on a monthly basis and you can then utilize the LAG window function to pull the values for the past 18 months for each month.
LAG(SUM(`patient_count`), 0) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 1) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 2) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 3) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 4) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 5) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 6) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 7) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 8) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 9) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 10) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 11) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 12) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 13) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 14) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 15) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 16) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`)) + LAG(SUM(`patient_count`), 17) OVER (PARTITION BY YEAR(`Date`), MONTH(`Date`) ORDER BY YEAR(`Date`), MONTH(`Date`))
Window functions is a feature switch and you'll need to talk with your CSM to get it enabled. I've done a writeup previously about lag window functions here: Domo IDEAs Conference - Beast Modes - Rolling Averages
Alternatively you could do this in a Magic ETL with a Rank & Window tile to simplify the card.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
If your dataset is showing totals for each day, you can do this in Magic ETL with just a few tiles. It would look something like this:
Use the formula tile to create a year column and month column
Use the group by tile to get totals for each month:
Use the Rank & Window tile create an 18-month total calculation by using the SUM and 18 preceding and sorting by year and month
This should get you what you want.
**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.1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 298 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 54 App Studio
- 40 Variables
- 678 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 33 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive