Index Data Calculation
Hi There,
I'd like to index data but my beast mode seems to be off. Below is what I'm trying to do but the calculation isn't working.
Index Formula = 100*(Current Revenue/Revenue from Jan 1, 2020)
Beast Mode = 100 * (SUM(`revenue`) / SUM(CASE WHEN `day` = '01/01/2020' THEN sum(`revenue`) END))
Any help is appreciated!
Comments
-
It looks like a simple syntax issue:
100 * (SUM(`revenue`) / SUM(CASE WHEN `day` = '01/01/2020' THEN sum(`revenue`) ELSE 0 END))
----------
Serving up data insights since 2002...0 -
Hi @user01052
A couple issues with your beast mode. The first being you're comparing a date to a string which doesn't always work well. The second and most imporatantly is that your beast mode runs on a row by row basis so your denominator would always be null for dates after the first snice the dates aren't the first and you don't have an else clause (which @eric_etumos fixes with his contribution making it 0). But it still won't let you go back to the first of the year since it's a different row.
However! To fix this we can use some windowing functions within a beast mode and coupling that with a case statement we can pull the data from the first of the year. I've tried to write this in such a way that it'll work going forward in the future (2021, 2022 etc) without having to edit the beast mode each year. Assuming your index date is always the first of the year.
100 * SUM(`Revenue`) / SUM(SUM(CASE WHEN DAY(`Date`) = 1 and MONTH(`Date`) = 1 THEN `Revenue` ELSE 0 END)) OVER (PARTITION BY YEAR(`Date`))
I'm not certain if windowing functions have made it out of beta yet at this point but you can reach out to your CSM to get it enabled in your instance.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
@eric_etumos wrote:It looks like a simple syntax issue:
100 * (SUM(`revenue`) / SUM(CASE WHEN `day` = '01/01/2020' THEN sum(`revenue`) ELSE 0 END))
EDIT:: i need to read everyone's responses before i start replying ... looks like @GrantSmith beat me to it...
The ELSE clause is a red herring.
If you take the SUM of a column containing NULLS, SQL will gracefully handle that. @eric_etumos , I believe you're thinking of what happens when SQL across two columns at the row-level
ex
SELECT col1 + col2_contains_NULL ... which will result in that ROW returning NULL.
whereas
SELECT sum(col2_containsNULL) ... would return the sum of non NULL rows.
either way, i don't believe that's the crux of the issue.
@GrantSmith sorted you out.
This is just a permutation of a percent of total calc with a CASE statement.
https://www.youtube.com/watch?v=ZPf41Fjn1H8&feature=youtu.be
cc @swagner
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"1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 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