Graph with Daily Total and Cumulative Total Bars
I am trying to recreate the below bar graph (from Excel) in Domo. In the below picture, the orange bar shows the 'Billed Amount' for that day (numbers along the bottom represent the day of the month). The gray bar shows the cumulative amount billed thus far that month (i.e. the second gray bar shows the sum of Day 1 and Day 2's Billed Amounts, the third gray bar shows the sum of Day 1, 2, and 3 Billed Amounts, and so on).
Thus far I have been unable to come up with a beast mode in Domo that will calculate this cumulative bar. Surely this must be possible; I am assuming I'm just missing something.
Any help, suggestions, or advice would be appreciated!
Thanks!
Best Answer
-
This is a pretty common issue with Beast Modes. When you are thinking about when to try to tackle something with a beastmode calculation, it is important to understand that these calculations can only look at one row of data to perform the calculation.
To create a running total, you will need to add some transforms in a MySQL data flow. This is how I would create a running monthly total:
tranform 1:
create procedure runningtotal()
BEGINSET @runtot:=0;
CREATE TABLE running_total AS
SELECT
q1.d as `Date`
,q1.c as `Billed Amount`
,(@runtot := @runtot + q1.c) AS `Cumulative Billed Amount (MTD)`
FROM
(SELECT
DAYOFMONTH(`Date`) AS d
,`Billed Amount`AS c
FROM table_name
WHERE MONTH(`Date`)=MONTH(CURDATE())
GROUP BY d
ORDER BY d) q1;
endtransform 2:
call runningtotal()
transform 3:
SELECT * FROM running_total
Hope that helps
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1
Answers
-
This is a pretty common issue with Beast Modes. When you are thinking about when to try to tackle something with a beastmode calculation, it is important to understand that these calculations can only look at one row of data to perform the calculation.
To create a running total, you will need to add some transforms in a MySQL data flow. This is how I would create a running monthly total:
tranform 1:
create procedure runningtotal()
BEGINSET @runtot:=0;
CREATE TABLE running_total AS
SELECT
q1.d as `Date`
,q1.c as `Billed Amount`
,(@runtot := @runtot + q1.c) AS `Cumulative Billed Amount (MTD)`
FROM
(SELECT
DAYOFMONTH(`Date`) AS d
,`Billed Amount`AS c
FROM table_name
WHERE MONTH(`Date`)=MONTH(CURDATE())
GROUP BY d
ORDER BY d) q1;
endtransform 2:
call runningtotal()
transform 3:
SELECT * FROM running_total
Hope that helps
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1 -
I am trying to use these same transforms to create a Running Total column for my store sales column--I have thirty stores and would like to have a column that shows each store's cumulative total sales for the month as of each date.
However, when I try to use these transforms, it only returns values for the first store in my source dataset. It just stops once it reaches the end of the first store's data and does not continue summing and such for the 29 other stores.
Would you have any idea why this is happening? Is there something I need to change about the transforms so that it looks at all of my dataset, not just the first store's information?
Screenshot below:
If you keep scrolling down in the preview, it only shows Oregon data--it does not go on to do the same for our other stores.
0 -
The previous solution was for a scenario where there was only one store. You would need to use the amazon redshift data flow option so that you could set up a windowed function. You could also possibly accomplish this via a magic ETL now, but I have not used the windowed function there much yet. Let me play with it a bit and I will see if I can come up with something for you
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
Thanks @ST_-Superman-_--another dojo member provided me with a MySQL statement that appears to be working, so I think I am good to go now! But thank you for responding and looking into this for me!
0 -
that's great @kbota. Any chance you could share here?
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
Yes, the MySQL statement is as follows:
SELECT
a.*,
(SELECT SUM(`Sales 2017`) from retail_sales_2016_to_present_joined as b where a.`Date_1` >= b.`Date_1` and a.`Store Location_1` = b.`Store Location_1` AND YEAR(a.`Date_1`) = YEAR(b.`Date_1`) AND MONTH(a.`Date_1`) = MONTH(b.`Date_1`) ) as 'Sales 2017 MTD'
FROM retail_sales_2016_to_present_joined as a0 -
I read this post and had a very similar problem. Hoping you guys can help.
I have a dataset listed below:
Year Gain Loss Net
1999 10 5 5
2000 15 20 -5
2001 12 9 3
2002 19 8 11
2003 17 21 -4
2004 18 3 15
I need to create a new column that has a sum of all active clients for that year:
Year Gain Loss Net Active
1999 10 5 5 5
2000 15 20 -5 0
2001 12 9 3 3
2002 19 8 11 14
2003 17 21 -4 10
2004 18 3 15 25
I can't seem to figure this out in ETL or BeastMode.
My other problem is that I created this dataset using ETL so now the Year field is recognized as a Whole Number field instead of a Date Field.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 296 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 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
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive