%change Year over Year
Hi all,
I am trying to make a card where I will have bars for total premium by year, and one line which will show % change betwen years (current to previous, previous to two years ago etc.). Do you have any advice how to do it, I tried to find solution on Dojo and Domo support but they point me to PoP knowledge base page.
Thank you in advance.
Comments

I built a walkthrough for something similar on another post. Check out this link:
https://dojo.domo.com/t5/CardBuilding/RePeriodoverPeriodusingstackedbars/mp/30479#M3655
Obviously instead of doing one by month, you'll need to tweak it to show years if thats what you're wanting.
For your % change calculation (starting with "Current Period / Previous Period  1" as your Variance calculation) you'll want to build out a Case When for whatever X period you decide.
So if you're showing X1 as 2016 vs 2015 and X2 is 2016 vs 2017 you can do this:
CASE WHEN year = 2016
THEN SUM(2016 metric) / SUM (2015 metric)  1
WHEN year = 2017
THEN SUM(2017 metric / SUM (2015 metric)  1
ENDBut instead of defining a specific year, you can do DATE_SUB(CURRENT_DATE(), INTERVAL 1 year) for 2017.
I know that's a lot of info to digest, just let me know if you have any questions.
Sincerely,
Valiant
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 
Good morning Valiant,
I am trying to implement the code you sent me into my function.
First I made this:
CASE WHEN `Type` = 'Current'
THEN YEAR(CURDATE())
WHEN `Type` = 'Previous_Yr'
THEN YEAR(DATE_ADD(CURDATE(), INTERVAL  1 YEAR))
WHEN `Type` = '2_Yrs_Ago'
THEN YEAR(DATE_ADD(CURDATE(), INTERVAL  2 YEAR))
WHEN `Type` = '3_Yrs_Ago'
THEN YEAR(DATE_ADD(CURDATE(), INTERVAL  3 YEAR))
WHEN `Type` = '4_Yrs_Ago'
THEN YEAR(DATE_ADD(CURDATE(), INTERVAL  4 YEAR))
WHEN `Type` = '5_Yrs_Ago'
THEN YEAR(DATE_ADD(CURDATE(), INTERVAL  5 YEAR))
ENDAnd then:
CASE WHEN `Type` = 'Current'
THEN (SUM(`Premium`) WHERE `Type` = 'Current') / (SUM(`Premium`) WHERE `Type` = 'Previous_Yr')  1
WHEN `Type` = 'Previous_Yr'
THEN (SUM(`Premium`) WHERE `Type` = 'Previous_Yr') / (SUM(`Premium`) WHERE `Type` = '2_Yrs_Ago')  1
ENDBut I am getting an error:
This calculation contained a syntax error.
Am I close? ?
Thank you,
Marko.0 
The second statement is incorrect because of the WHERE clauses.
Can you give me a few lines of example data using your available column names? That should help me better understand what you're working with and I can tailor my answer to suit.
Sincerely,
Valiant
0 
I am trying to get Premium of every single row where Type is certain year. Of course, let me send you example.
Thank you,Marko.
0 
0

Ok, so while we could go down a long path of lots of sql transform and beast modes to get this answer, let's see if the simple solution works first.
In your data, can you edit the data (either using an ETL or SQL transform) to convert each year (ie, 2013) to something like this (20130101). The end result being that we want to convert that column to a recognized date column type. Once you have that, you can go to the card, choose the Period over Period type and select 'Variance bar line'. Using the Year as your X axis and the Premium as your Y, adjust the time selection to match the following:
Once you have that, you'll have bars for each year compared to the previous year and a variance (% change) line for your chart.
Let me know if that will work for your needs,
Valiant
1 
I already have made this one, but we would like to have one bar for each year and one line showing % change between current and previous year. That's why I am trying to find a solution for this.
Thank you very much for your help,Marko.
0 
ok, so in that case, you're going to need to create to do the following steps via either ETL or SQL transforms:
1. Sum your premiums by year
SELECT `Year`, SUM(`Premium`) as 'PremiumTotal', `Year`1 AS 'LastYear'
FROM dataset
GROUP BY `Year`2. Add a 'Last Years Premiums' to your dataset
SELECT a.*,
b.`PremiumTotal` AS 'LastYearPremium'
FROM transform1 AS a LEFT JOIN transform1 AS b ON a.`Year` = b.`LastYear`With that result you'll use Year as your X axis and your calc for YoY % change is
`PremiumTotal` / `LastYearPremium`  1
Hope that helps,
Valiant
2 
I tried to make a new dataset but output shows ammount of next year into last year field instead of last year amount. Confused!
0
Categories
 10.5K All Categories
 3 Connect
 913 Connectors
 250 Workbench
 458 Transform
 1.7K Magic ETL
 69 SQL DataFlows
 476 Datasets
 183 Visualize
 249 Beast Mode
 2.1K Charting
 11 Variables
 16 Automate
 354 APIs & Domo Developer
 88 Apps
 3 Workflows
 20 Predict
 5 Jupyter Workspaces
 15 R & Python Tiles
 245 Distribute
 62 Domo Everywhere
 242 Scheduled Reports
 20 Manage
 41 Governance & Security
 168 Product Ideas
 1.2K Ideas Exchange
 9 Community Forums
 27 Getting Started
 14 Community Member Introductions
 55 Community News
 4.5K Archive