Graph with Daily Total and Cumulative Total Bars

Reply
Yellow Belt

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).

 

2017-09-01 14_51_26-Book1 - Excel.png

 

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!


Accepted Solutions
Major Brown Belt

Re: Graph with Daily Total and Cumulative Total Bars

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()
BEGIN

SET @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;
end

 

transform 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.” -Superman
______________________________________________________________________________________________

All Replies
Major Brown Belt

Re: Graph with Daily Total and Cumulative Total Bars

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()
BEGIN

SET @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;
end

 

transform 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.” -Superman
______________________________________________________________________________________________
Yellow Belt

Re: Graph with Daily Total and Cumulative Total Bars

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:2.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.

 

 

Major Brown Belt

Re: Graph with Daily Total and Cumulative Total Bars

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.” -Superman
______________________________________________________________________________________________
Yellow Belt

Re: Graph with Daily Total and Cumulative Total Bars

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!

Major Brown Belt

Re: Graph with Daily Total and Cumulative Total Bars

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.” -Superman
______________________________________________________________________________________________
Yellow Belt

Re: Graph with Daily Total and Cumulative Total Bars

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 a

Highlighted
White Belt

Re: Graph with Daily Total and Cumulative Total Bars

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.

Announcements
New to Dojo Please update your Dojo handle and personal settings. Click here!