Beast Mode - Separate Running Total into Daily Values
I'm using the Search Users report in the Twitter connector to pull the number of followers for a particular user. I have it set to run daily and append the new data, which gives me the running total for twitter followers for the given user. I'd like to create a beast mode calculation that will give me the number of new followers on a daily basis so that I can create a chart that shows new followers by day. In order to do that I need to look at how many followers the user had on a given day based on the "_batch_last_run_" date and subtract the number of followers from the prior day. I can calculate it for today versus yesterday, but I'd like to be able have it calculate for all days in the date range that the Domo user defines. Any ideas on how to create a beast mode calculation that will do that? I'd also be open to calculating it via a dataflow.
Thanks!
Best Answer
-
Hi @nlinnell,
I responded to this on Monday, but apparently it didn't save.
Assuming you are using the MySQL DataFlow, there are few things that need to be done to get the script to work.
First, when I copied the script from the message board into a dataflow, I noticed that it put in <br>HTML tags, they need to be removed. Unfortunately they aren't seen when you paste it in. so I went to the beginning of each line and deleted to the end of the previous line and then hit enter.
Second, in MySQL you need to use the back tick ` (it is in the upper left of the keyboard, next to the 1) for the field delimiter. Here is an example of what you had:
a."_Batch_Last_Run_",
it needs to be this:
a.`_Batch_Last_Run_`,
Third, when aliasing the table, you don't need a delimiter unless it contains a space. So your line:
from twitter_user_profile_metrics AS "a"
needs to be this:from twitter_user_profile_metrics AS a
Fourth, you made to accomodate for a DateTime to just a date, by use the date() function. like so:
date(a.`_Batch_Last_Run_`)
so for MySQL it should look like this:
SELECT
a.`_Batch_Last_Run_`,
a.`Followers Count`,
(b.`Followers Count` - a.`Followers Count`) AS "New Follower Count"
from user_profile_metrics AS a
join user_profile_metrics AS b on Date(a.`_Batch_Last_Run_`) = Date(ADDDATE(b.`_Batch_Last_Run_`, INTERVAL 1 DAY))in RedShift, it would need to look like this:
SELECT
a."_Batch_Last_Run_",
a."Followers Count",
(b."Followers Count" - a."Followers Count") AS "New Follower Count"
from user_profile_metrics AS a
join user_profile_metrics AS b on Date(a."_Batch_Last_Run_") = Date(DATEADD(DAY, -1, b."_Batch_Last_Run_"))hope this helps
2
Answers
-
I am looking into this, and will let you know what I find.
0 -
BeastMode only calculates on one row, so what you would need to do is build a DataFlow that would either
a) do the calculation and give you a `New Follower` field
or
b) pull in the previous day's `Follower Count` and then do a Beast mode to perform the calculation
Using a join to the same table but 1 day behind
Select a.`_Batch_Last_Run_`, a.`Followers Count`, b.`Followers Count`-a.`Followers Count` as 'New Follower Count'
from `Twitter Search User` a
join `Twitter Search User` b on a.`_Batch_Last_Run_` =ADDDATE(a.`_Batch_Last_Run_`, INTERVAL 1 DAY)
0 -
Thanks for the reply. I've tried to take your example script and use it in a transform to make the calculations, but I can't seem to write the correct script (I'm a novice SQL user). I first tried to take the exact script and only swap the input dataset reference. I then tried to modify the script, but I still haven't been able to get it to work. Below is what I currently have in place. The current error I receive says "The database reported a syntax error. ERROR: syntax error at or near "1" Position: 358." Any help in getting the correct script woudl be greatly apprechiated.
SELECT
a."_Batch_Last_Run_",
a."Followers Count",
(b."Followers Count" - a."Followers Count") AS "New Follower Count"
from twitter_user_profile_metrics AS "a"
join twitter_user_profile_metrics AS "b" on a."_Batch_Last_Run_" = ADDDATE(a."_Batch_Last_Run_", INTERVAL 1 DAY)0 -
Hello @nlinnell,
It looks like your syntax below is written for RedShift dataflows. The example was written for MySQL dataflows.
RedShift does not support ADDDATE(). Please try using DATEADD() in your join.DATEADD( datepart, interval, {date|timestamp} )
Here is a link to RedShift documentation that explains how to use this function.
http://docs.aws.amazon.com/redshift/latest/dg/r_DATEADD_function.html
Please let me know if you still receive an error after making this change.**Say “Thanks" by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Hi @nlinnell,
I responded to this on Monday, but apparently it didn't save.
Assuming you are using the MySQL DataFlow, there are few things that need to be done to get the script to work.
First, when I copied the script from the message board into a dataflow, I noticed that it put in <br>HTML tags, they need to be removed. Unfortunately they aren't seen when you paste it in. so I went to the beginning of each line and deleted to the end of the previous line and then hit enter.
Second, in MySQL you need to use the back tick ` (it is in the upper left of the keyboard, next to the 1) for the field delimiter. Here is an example of what you had:
a."_Batch_Last_Run_",
it needs to be this:
a.`_Batch_Last_Run_`,
Third, when aliasing the table, you don't need a delimiter unless it contains a space. So your line:
from twitter_user_profile_metrics AS "a"
needs to be this:from twitter_user_profile_metrics AS a
Fourth, you made to accomodate for a DateTime to just a date, by use the date() function. like so:
date(a.`_Batch_Last_Run_`)
so for MySQL it should look like this:
SELECT
a.`_Batch_Last_Run_`,
a.`Followers Count`,
(b.`Followers Count` - a.`Followers Count`) AS "New Follower Count"
from user_profile_metrics AS a
join user_profile_metrics AS b on Date(a.`_Batch_Last_Run_`) = Date(ADDDATE(b.`_Batch_Last_Run_`, INTERVAL 1 DAY))in RedShift, it would need to look like this:
SELECT
a."_Batch_Last_Run_",
a."Followers Count",
(b."Followers Count" - a."Followers Count") AS "New Follower Count"
from user_profile_metrics AS a
join user_profile_metrics AS b on Date(a."_Batch_Last_Run_") = Date(DATEADD(DAY, -1, b."_Batch_Last_Run_"))hope this helps
2 -
Hello-
I'm trying to do something similar here, I have a dataset where I have a daily running total of FB Fans, and I'd like to break it down by daily fans gained/lost. I put the following into the mySQL transform, but it's failing whenever I run it.
SELECT
a.`Date`,
a.`Total Page Fans`,
(b.`Total Page Fans` - a.`Total Page Fans`) AS "Daily Page Fans"
from `fba_fans` AS a
join `fba_fans` AS b on Date(a.`Date`) = Date(ADDDATE(b.`Date`, INTERVAL 1 DAY))0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive