Dynamic user selected date comparison variance calculations
I am seeking support on ideas for the best way to allow a user to manually select one date span and then select a second date span for comparison, so that the visuals show the variance of $'s as well as % from the first time span selected and the second date span selected.
The user does not want pre built time span variance calculations they want to be able to explore any dates from this year and last year and see the variance. Whether its between yesterday and the day before, or from yesterday to same day last year.
Thanks for any thoughts and ideas.
Answers
-
You can track the calendar differences by using your primary date field and creating fields for year({datefield}, month({datefield}, monthname({datefield}) and the use aggregates in Magic ETL to calculate current year, previous year, previous 2 years, etc. How deep you decide you need is based on whether you need it down to week, day, hour, etc.
If you are comparing, then you want to do CYTD versus the PYTD.
So a current year aggregate would be something like:SUM(CASE WHEN YEAR(`date`) = YEAR(CURDATE())
THEN `amount`
ELSE 0
END)A previous year to date aggregate would be:
SUM(CASE
WHEN YEAR(`date`) = YEAR(CURDATE()) - 1
AND `date` < DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
THEN `amount`
ELSE 0
END)So if you are in June, previous year only calculates up through June of the previous year. And so on. From there you can find the deltas / differences and percentage differences.
And you can get further using variables but it gets more complex.** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **1 -
If you want to use variables, you could create variables for comparing date range A with date range B. You will need a start and end for A range, and a start and end for B range. Then use a beast most to identify what belongs to range A and what belongs to range B. Filter out the other.
CASE
WHEN `Date` BETWEEN `Start Date Range A` AND `End Date Range A` THEN 'A'
WHEN `Date` BETWEEN `Start Date Range B` AND `End Date Range B` THEN 'B'
ELSE 'Other'
ENDFind totals and variance and from that variance %. Account for dividing by zero in %.
SUM(CASE WHEN `Group` = 'A' THEN `Amount` ELSE 0 END)
SUM(CASE WHEN `Group` = 'B' THEN `Amount` ELSE 0 END)
SUM(CASE WHEN `Group` = 'B' THEN `Amount` ELSE 0 END)
- SUM(CASE WHEN `Group` = 'A' THEN `Amount` ELSE 0 END)
CASE
WHEN SUM(CASE WHEN `Group` = 'A' THEN `Amount` ELSE 0 END) = 0 THEN NULL
ELSE
(SUM(CASE WHEN `Group` = 'B' THEN `Amount` ELSE 0 END)
- SUM(CASE WHEN `Group` = 'A' THEN `Amount` ELSE 0 END))
/ SUM(CASE WHEN `Group` = 'A' THEN `Amount` ELSE 0 END)
END** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **1 -
awesome thanks I will give this variable approach a try
0
Categories
- All Categories
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 665 Datasets
- 120 SQL DataFlows
- 2.3K Magic ETL
- 827 Beast Mode
- Visualize
- 2.6K Charting
- 90 App Studio
- 46 Variables
- Automate
- 198 Apps
- 489 APIs & Domo Developer
- 97 Workflows
- 24 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 119 Domo Everywhere
- 284 Scheduled Reports
- 11 Software Integrations
- Manage
- 145 Governance & Security
- 13 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive