week on week % change beast mode
date examples are based on writing today  6th September.
my aim is to create a beastmode, which can ultimately be applied to any metric, which shows the weekonweek % change. this value would be able to be displayed in a table by date(week) or as a KPI card which would be filtered to show data for last week.
the goal is to have the working beastmode for the values which are precalculated in the 'period over period' cards. I have attached the vairance bar line example I use  I would like the variance %s shown here as a beastmode value.
example:
a = sum the complete last week revenue (e.g. 26th August  1st September *Domo weeks run Sunday to Saturday)
b = sum the complete previous to last week revenue (e.g. 19th August  25th August)
wow%change = sum(a) / sum(b) 1
e.g. 1500 / 1350  1 = 11.1%
I found some details on the domo knowledge board but cannot get the formula to work. I get a divide by zero error. example below...
(CASE
WHEN ((year(`activity_date`)=year(curdate())) AND (weekofyear(`activity_date`)=weekofyear(CURDATE())))
THEN `revenue`
END
/
CASE
WHEN (weekofyear(curdate())=1)
THEN (CASE WHEN ((year(`activity_date`)=(year(curdate())  1)) AND (weekofyear(`activity_date`)=52))
THEN `revenue` END )
ELSE (CASE WHEN ((year(`activity_date`)=year(curdate())) AND (weekofyear(`activity_date`)=(weekofyear(CURDATE()) 1)))
THEN `revenue` END )
END) 1
Comments

Hi @jonathanlooker, the reason you can get a divide by zero error is becuase you have division in your beast mode. A denominator can never equal 0, else Domo throws an error.
My suggestion is you take the entire denominator and apply a case statement up front if the denominator = 0 then the value will be 0. You numerators and denominators can contain additional case statements, you just need one that encompises the entire formula.
CASE WHEN Denominator = 0 THEN 0 ELSE
Numerator
/
Denominator
END
Thanks,
Josh
1 
@jonathanlooker In addition to what @jstan said about adding a WHEN clause to prevent divide by zero errors, you have to make sure that the date range on your card is big enough to contain all data being compared. For example, if today (9/13/18) I am looking at data for last week MonSun (9/3/189/9/18) vs the previous period (8/27/189/2/18), my card has to contain data from 8/27/18 and thereafter. Filtering the card for "last 22 days" or "last 3 weeks" should contain all of this data and then update automatically as you head into a new week.
1
Categories
 All Categories
 1.6K Product Ideas
 1.6K Ideas Exchange
 1.5K Connect
 1.2K Connectors
 288 Workbench
 4 Cloud Amplifier
 8 Federated
 2.8K Transform
 94 SQL DataFlows
 594 Datasets
 2.1K Magic ETL
 3.6K Visualize
 2.4K Charting
 671 Beast Mode
 42 App Studio
 34 Variables
 645 Automate
 165 Apps
 434 APIs & Domo Developer
 42 Workflows
 4 DomoAI
 31 Predict
 12 Jupyter Workspaces
 19 R & Python Tiles
 378 Distribute
 107 Domo Everywhere
 266 Scheduled Reports
 5 Software Integrations
 111 Manage
 108 Governance & Security
 8 Domo University
 23 Product Releases
 Community Forums
 39 Getting Started
 29 Community Member Introductions
 95 Community Announcements
 4.8K Archive