I use Grafana (the version is 8.3.3) with the Google BigQuery datasource.
I can't display a graph with a monthly distribution (with the macro $__timeGroup)
My query :
SELECT * FROM ( SELECT
$__timeGroup(usage_start_time, 1M),
project.id AS metric,
SUM(cost) AS value FROM
`project.view_v3` WHERE
$__timeFilter(usage_start_time) GROUP BY 1, 2 ORDER BY 1 ASC ) WHERE value > 0
With a visualization by table, it seems to work, but not in graphical mode :
enter image description here
thanks for helping,
Regards,
Didier
Related
I need some help with building the guage chart with the following requirements
I have a table in bq called dim_table as follows
I need to provide the Drop-down list on the the dimensions such that when user select the options, i need to refresh the user count percentage.
For example
When user selects gender as male, country as usa and age_bracket as all of the values, the total user count matching with those values is 12 out of the total value 43 and hence the percentage should 12/43 which is 27.90% in the guage chart
I have the following BQ query
select (cut_value/total_value)*100 as cut_percentage from (select sum(user_count) as cut_value from dim_table where gender in (data_studio_selected_gender_value) and country in (data_studio_selected_country_value) and age_bracket in (data_studio_selected_age_value) join select select sum(user_count) as total_value from dim_table on 1=1)
Question: How could I integrate the datastudio drop-down list values to the the above query in order to populate the guage chart
In data studio have two data sources:
dim_table which is the normal data source
total which is the custom BigQuery: sum(user_counts) as total, "" as empty from dim_table (it is also possible to duplicate the first dataset and hide here all fields except user_counts and add the extra field empty)
Blend these two tables together with the join key empty. Generate such a field in the dim_table with the formula ""
Add in the graph or table add a metric with the formula:
sum(user_counts)/avg(total)
You can apply the normal filter and do not have to worry about parameter to act like filtering.
I have a influxdb bucket full of stock prices and created wonderful dashboards in Grafana now.
I try for hours to get a chart in place, that shows the performance in percent instead of the stock price, but it does not work.
Query to get the price is very simple:
SELECT last("price") FROM "stock_data" WHERE ("Name" = 'XYZ') AND $timeFilter GROUP BY time($__interval) fill(previous)
How do I get a performance chart now out of it? It tried (and I believe that is close)
SELECT ( last("price") / first(price)) * 100 FROM "stock_data" WHERE ("Name" = 'XYZ') AND $timeFilter GROUP BY time($__interval) fill(previous)
The issue comes with the "/ first(price)"!
All I really need is the first value of the whole query.
Any help?
I have a grafana dashboard that charts a bunch of data on 2 query's, this is one below:
SELECT
"time" AS "time",
metric AS metric,
value
FROM
slipstream_volttron
WHERE
$__timeFilter("time") AND
metric ~ 'slipstream_internal/slipstream_hq/.*/SA-F$'
ORDER BY 1,2
And this is the other query:
SELECT
"time" AS "time",
metric AS metric,
value
FROM
slipstream_volttron
WHERE
$__timeFilter("time") AND
metric ~ 'slipstream_internal/slipstream_hq/.*/Discharge Air Flow$'
ORDER BY 1,2
Would anyone know how I could modify this into one SQL expression for a totalization? Instead of 50 different lines on my chart, just one line of all variables added together. The data is air flow readings and I am trying to figure out how to just plot a totalized air flow reading of all data, hopefully that makes sense for anything */Discharge Air Flow and .*/SA-F
I'm guessing your database isn't MSSQL as I don't recognise ~ as a valid comparison operator so my answer is a bit of a guess based on what would work for MSSQL. I think this should give you the results you are looking for:
SELECT
"time" AS "time",
SUM(value)
FROM
slipstream_volttron
WHERE
$__timeFilter("time") AND
(metric ~ 'slipstream_internal/slipstream_hq/.*/Discharge Air Flow$'
OR metric ~ 'slipstream_internal/slipstream_hq/.*/SA-F$')
GROUP BY time
ORDER BY 1
Hello wonderful person!
I've followed this guide to import google ads campaign info to a BigQuery database.
My goal is to create a simple query that can be stored as a view and accessed from Data Studio to make a report. But some fields like AverageCpm are always set to 0.
I also have a data studio report made using google ads as source for reference and I can access all the campaigns from the google ads platform.
Here is the query I'm working on:
SELECT
c.ExternalCustomerId,
c.CampaignName as name,
c.CampaignStatus,
cs.date as dia,
SUM(cs.Impressions) AS Impressions,
SUM(cs.Interactions) AS Interactions,
AVG(cs.AverageCpm) AS CPM,
SUM(cs.Cost) AS Cost
FROM
`<DB>.google_ads.Campaign_<ACCOUNT_ID>` c
LEFT JOIN
`<DB>.google_ads.CampaignStats_<ACCOUNT_ID>` cs
ON
(c.CampaignId = cs.CampaignId
AND cs._DATA_DATE BETWEEN
DATE_ADD(CURRENT_DATE(), INTERVAL -80 DAY) AND DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY))
WHERE
c._DATA_DATE = c._LATEST_DATE
and c.CampaignName = 'THE_NAME_OF_MY_CAMPAIGN'
GROUP BY
1, 2, 3 , 4
ORDER BY
CampaignName, dia
The field Impressions, returns with a value that is consistent with my reference datastudio report and the info I see in google ads stats, so I feel I'm in the right track.
My problem is that some fields like CampaignStats.AverageCpm , CampaignStats.Cost are always 0.
For example, the query:
Select * from `<DB>.google_ads.p_CampaignStats_<ACCOUNT_ID>` where AverageCpm >0;
Returns with no results.
I'm thinking permission problems? But I have administrator access to all the company's accounts.
Database is backfilled correctly.
I've tried generating a new dataset: Same problem and I don't see if there is a way to configure how google makes the imports.
What else could it be? What else can I do?
Thank you very very much!
Answer by Roman Petrochenkov, check his youtube channel he is the best.
AVG(cs.AverageCpm) AS CPM, Is not correct
Since average of averages is not average of the total.
You need to calculate CPM manually as SUM(Impressions)/SUM(NULLIF(Cost, 0)) as CPM
Although, I would recommend against calculating it in the BQ and would recommend to calculate int in the BI (data studio in this case).
I request your help for an issue beyond my current skills...
I'm using Google Big Query to store analytics data about my website, and to calculate the revenue I have a quite difficult query to build.
We have the field %product% which is formatted as following :
;%productID%;%productQuantity%;%productRevenue%;;
If more than one product has been bought, the different products data will be delimited by ",", which can give this :
;12345678;1;49.99;;,;45678912;1;54.99;;
;45678912;2;59.98;;,;14521452;2;139.98;;,;12345678;2;19.98;;
;14521452;1;54.99;;
The only way to calculate the revenue is to sum all the different %productRevenue% from a line and store this into a column.
I have no idea how to do it just with a SQL query... Maybe with RegEx ? Any idea ?
I'd like to create a view with that info to easily pull the data into PowerBI then. But maybe I should process that with M directly in PBI ?
Thanks a lot,
Alex
Below is for BigQuery Standard SQL
#standardSQL
SELECT
SPLIT(i, ';')[OFFSET(1)] productID,
SUM(CAST(SPLIT(i, ';')[OFFSET(2)] AS INT64)) productQuantity,
SUM(CAST(SPLIT(i, ';')[OFFSET(3)] AS FLOAT64)) productRevenue
FROM `project.dataset.table`,
UNNEST(SPLIT(product)) i
GROUP BY productID
if to apply to sample data from your question - output is
Row productID productQuantity productRevenue
1 12345678 3 69.97
2 45678912 3 114.97
3 14521452 3 194.97