Hot to get data from previous year in Google Looker Studio (Data Studio) when using Supermetrics (Apps Script Add-on) connector - formula

I'm pulling data from Google Analytics for 150+ accounts, using Supermetrics for Looker Studio.
Now I want to create a table with Y/Y data, e.g:
Date
Date_last_year
Revenue
Revenue_last_year
Cost
Cost_last_year
1 dec 2023
1 dec 2022
1000
980
500
550
I've added a calculated field to the data source: Date_last_year = DATE(DATETIME_SUB(Date, INTERVAL 1 YEAR)) which gives me the correct last year's date.
However, when I try to blend the data source with itself, doing an inner join on date_last_year and date, I get no data.
I'm guessing the issue is that I can't add Date as a dimension under Date Range
This option shows up if I e.g. use a GA view as source data:
Is there any way to make this work using Supermetrics for Looker Studio?
I don't have the option of pulling the GA data into e.g. BigQuery, so I need to find a solution using the existing setup :(

Related

How to 'Add / Sum / Total / Calculate' dynamic tables in google app maker

It's probably the simplest thing in the world but I can't seem to add/sum/calculate tables in App Maker. I have attached an image of the App preview. I will try to keep this simple. The page has 3 data sources as follows:
Apex_customer_po - This is where our employee's input customer purchase orders including the PO number (string), the overall value of the PO (number), and the details (string)
Apex_customer_po_wo_details - Purchase orders are often broken up by our customer in to multiple work orders (WO), a task break down each with it's own values including Date (date), WO number (string), WO amount (number), details (string)
Apex_customer_po_wo_costing - This is where we keep track of what work we've done and how much of each work order's money we've used. The fields include a reference number(string), parts price (number), Part details (string), Labour hrs (number), Labour rate (number), Total labour (number), and Invoice total (number), Overall total of all invoices for the work order (number)
My data relations are as follows:
Apex_customer_po
Apex_customer_po_wo_details (One Apex_customer_po to Many Apex_customer_po_wo_details)
Apex_customer_po_wo_costing (One Apex_customer_po_wo_details to Many Apex_customer_po_wo_costing)
Shows the general configuration of the PO app preview mode. I includes 2 work orders each with their associated invoices
Shows the general configuration of the Layout view of the app page
I have figured out how to calculate the cost of my labour:
#datasource.item.Labour_total = #datasource.item.Labour_time * #datasource.item.Labour_rate
I have figured out how to calculate the total of each invoice:
#datasource.item.Invoice_total = #datasource.item.Parts_amount + (#datasource.item.Labour_time * #datasource.item.Labour_rate)
But I can't for the life of me figure out how to 'Add / Sum / Total / Calculate' the individual invoices from each Work Order to get a total value.
I've tried unsuccessfully to use reduce and a bunch of other methods, but I can't ever seem to get the syntax correct even on basic 1+1 type calculations. I don't have much experience in app maker but I've been doing fine and loving it... until now.
Update 001:
I have managed to get a reduce function to perform a simple table addition for me based off the following blog post. blog.supportgroup.com/google-app-maker-cold-calculations - And the ball is rolling again. Now I need to rework how my data sources are set-up changing the numbers to strings –
Update 002:
I managed to get the reduce function to work in my app. However it totals the values from the selected cells across the data source. For example I have a PO, lets call it PO#1 and there are 5 items that total $5. When I start a new PO#2, it carries over the total of PO#1. So it calculates the entire data source regardless of the fact that it's 2 different PO#'s and I don't know how to make it stop. The code I have used is as follows
#datasource.item.Total = getFormatMoney((#datasources.Apex_customer_po_wo_costing.items).reduce((b,a) => Number(a.Parts_amount) + (Number(a.Labour_rate) * Number(a.Labour_time))+ Number(b) , 0 ),2,",",".")
The getFormatMoney(),2,",",".") is a client side java script that formats the currency
Thanks in advance for the assistance.
UPDATE 003:
I am now trying to do this in a different way with a calculated Data source and I am following this tutorial:
YouTube 7.33min long - Totals in Drive Tables tutorial
I have re-created the app step by step but I am getting the following error regarding my SQL query code:
E Mon Nov 18 13:38:49 GMT-700 2019 Exception: Malformed SQL. More
information: Error with SQL statement: You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near var totals = (wholesale:0, retail:0, profit:0); var records = app.models.autos. at line 1.
E Mon Nov 18 13:38:49 GMT-700 2019 Executing query for datasource
totals: (Error) : Malformed SQL. More information: Error with SQL
statement: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near var totals = (wholesale:0, retail:0, profit:0); var records =
app.models.autos. at line 1.
E Mon Nov 18 13:38:49 GMT-700 2019 Executing query for datasource
totals failed.
My code in my data source is as follows:
var totals = {wholesale:0, retail:0, profit:0};
var records = app.models.autos.newQuery().run();
records.forEach(function( item ){
totals.wholesale += item.wholesale;
totals.retail += item.retail;
totals.profit += (item.retail - item.wholesale);
});
var record = app.models.totals.newRecord();
record.wholesale = totals.wholesale;
record.retail = totals.retail;
record.profit = totals.profit;
return [record];
Anyone have any thoughts on what the mistake is?
Update 004
Success - The data source type needed to be a "Calculated" type not a "Calculated SQL". Now I am going to see if I can apply this new type of calculation to my existing problem.
It seems like the way to go on this is the calculated model route the tutorial I linked in Update 003 is a solid path to go down.

Google analytics dynamic MTD, YTD, last month "start-date" value

I'm trying to access my google analytics app data in Klipfolio through the google analytics query API.
I would like create data sources to dynamically pull MTD, YTD, and last months data.
So far, I've only been able to use today, yesterday, NdaysAgo, and YYYY-MM-DD format for the "start-date" attribute.
Is there a value I can use for "start-date" that will dynamically pull the MTD, YTD, or last months data.
Thanks
For MTD:
start-date={date.startOfMonth}
end-date={date.today}
For YTD:
start-date={date.startOfYear}
end-date={date.today}
For last month:
start-date={date.addMonths(-1).startOfMonth}
end-date={date.addMonths(-1).endOfMonth}

How to add expression calculated field with query

I am using an Access 2010 DB and have a simple table with the following data:
I would like to add by query additional field named batch number. The batch number shall divided my series into batches. While if number of pipes is 0 then the batch number is 0, and if the number is between zeros the serie should get the same batch number. please see attached image.
when creating a new table on design mode after entering file name when choosing the type of the field in the data type column you choose calculates Don’t know if it’s the same on access
2010 but it’s work on 2013 et 2016

How to set the aging interval and # of days for AP Aging Summary

I don't see how to specify an interval in the Desktop SDK for AgingReportQueryRq AgingReportType of APAgingSummary. It defaults to 30 day intervals and 90 limit. I don't want those. I can see how to change them in the UI, but I need to generate the report using the SDK
Thanks.
Use ReportPeriod or ReportDateMacro to pick the days you want.
The SDK does not offer access to set the Interval or Through fields like you can in the QuickBooks UI.
You should be able to generate the data and create your own report. I would suggest running an Open Invoices report. You can specify to have the open balance as of report end date or as of today.
IGeneralDetailReportQuery rpt = MsgRequest.AppendGeneralDetailReportQueryRq();
rpt.GeneralDetailReportType.SetValue(ENGeneralDetailReportType.gdrtOpenInvoices);
rpt.IncludeColumnList.Add(ENIncludeColumn.icDate);
rpt.IncludeColumnList.Add(ENIncludeColumn.icDueDate);
rpt.IncludeColumnList.Add(ENIncludeColumn.icName);
rpt.IncludeColumnList.Add(ENIncludeColumn.icOpenBalance);
rpt.ReportOpenBalanceAsOf.SetValue(ENReportOpenBalanceAsOf.robaoReportEndDate);
rpt.ORReportPeriod.ReportPeriod.FromReportDate(/* FROM REPORT DATE */);
rpt.ORReportPeriod.ReportPeriod.ToReportDate(/* TO REPORT DATE */);

Unable to view uploaded timeseries data in UI chart

Running the Databus server from the command line I have successfully uploaded timeseries data via curl, and am able to query the same data with the api. I'm unable to view any of the data in the table in the UI. After selecting "My Databus" -> Tables is says "You do not belong to any groups that have tables yet. Add some groups, then tables!!!". Navigating to the Database and selecting the table -> chart no data comes back there either.
I have noticed that the query it issues is from a recent time range, while the data I loaded is for an earlier time period. Is there a default way to show the most recent data available in a table?
Is your table type relational or stream? If relational, what is the primary key?
If time series, this url will give you the last 10 values because of the parameter 10 and reverse=true.
http://[yourhost]/api/firstvaluesV1/10/rawdataV1/[yourtablename]?reverse=true
If relational table, you can retreive all values like so
http://[yourhost]/api/getdataV1/select+c+from+[yourtablename]+as+c
replace either urls [yourhost] and [yourtablename] values.
We do not use the tables page much. It is better to click in the specific database as in My Databus -> Databases and then click on the database that has your table. We are about to add a view data link in there showing most recent 1000 values or something like that. There is already a view chart which shows most recent 2 hours(again, we want to change that to most recent 1000 data points instead as well).

Resources