How to count a phrase in Big Query view - google-bigquery

I have fir-ui-af***:firestore_export dataset in my BigQuery project.
In this dataset, I have speech_raw_changelog table and speech_raw_latest view.
This is schema of speech_raw_latest view.
In data field which I marked with a red pen, there is JSON data.
This is an example of field and value in data.
I would like to count the number of ******ka#gmail.com in email field in this speech_raw_latest view.
I searched the Internet and found that I should use COUNT function, but I don't know how to use it to solve my problem.
Could you give me any advice, please?

Below is for BigQuery Standard SQL
SELECT COUNTIF(JSON_EXTRACT_SCALAR(data, '$.email') = 'ka#gmail')
FROM `project.dataset.speech_raw_latest`

Related

Grafana Status timeline not working with PostgresSQL and only one Query

I’m creating a dashboard in Grafana with data extracted from Google Servers and stored in a PostgresSQL Database.
In one of the visualization I would like to create a Status Timeline:
I have created a query in PostgresSQL which returns me the following table:
As my understanding goes, that is the data that is need to create a Status Timeline. (Time, count of a variable and name of the variable count).
But when I copy that query inside Grafana, the chart is not the same as I have imagined:
I don’t know what else to do or how to fix it.
Does anyone has faced this issue before or know how to solve it, in order to get a Status Timeline like the one showed above?
Thank you very much!
As you can see in your last image, the metric names used in the panel are the column names. The status values used are the column values. So you need a table result like that:
executed_on
dev
asia-dev
...
2022-06-07 12:00:00
1
4
...
...
...
...
...

Getting rid of date filter on BigQuery?

I'm trying to get rid of this particular date filter on BQ and have a date column instead (kindly check the red circle to see what I'm talking about)
This data was extracted from Microsoft (Bing) Ads using Supermetrics. Any idea how to tackle this? Let me know if you need more information. Thank you.
AK
So the string depicted in the red circle is part of the table name i.e. 2021111.
So to view all the data you will want to create a query that looks at all the tables like, but be careful as datasets can get BIG fast.
SELECT *
FROM `BINGADS_AGE_GENDER_*`
If you wanted to only combine a certain date range you could use
SELECT *
FROM `BINGADS_AGE_GENDER_*`
WHERE _table_suffix BETWEEN '20211001' and '20211101'
If you use this datasource within datastudio you can use the #DS_START_DATE and #DS_END_DATE parameters with the date picker.

Tableau count values after a GROUP BY in SQL

I'm using Tableau to show some schools data.
My data structure gives a table that has all de school classes in the country. The thing is I need to count, for example, how many schools has Primary and Preschool (both).
A simplified version of my table should look like this:
In that table, if I want to know the number needed in the example, the result should be 1, because in only one school exists both Primary and Preschool.
I want to have a multiple filter in Tableau that gives me that information.
I was thinking in the SQL query that should be made and it needs a GROUP BY statement. An example of the consult is here in a fiddle: Database example query
In the SQL query I group by id all the schools that meet either one of the conditions inside de IN(...) and then count how many of them meet both (c=2).
Is there a way to do something like this in Tableau? Either using groups or sets, using advanced filters or programming a RAW SQL calculated fiel?
Thanks!
Dubafek
PS: I add a link to my question in Tableu's forum because you can download my testing workbook there: Tableu's forum question
I've solved the issue using LODs (specifically INCLUDE and EXCLUDE statements).
I created two calculated fields having the aggregation I needed:
Then I made a calculated field that leaves only the School IDs that matches the number of types they have (according with the filtering) with the number of types selected in the multiple filter (both of the fields shown above):
Finally, I used COUNTD([Condition]) to display the amounts of schools matching with at least the School types selected.
Hope this helps someone with similar issue.
PS: If someone wants the Workbook with the solution I've uploaded it in an answer in the Tableau Forum

Extracting Data from a Multi-Data Column in SQL

I'm creating a sales leaderboard in HOLISTICS and the column "user_id" is a multi-data column.
Here's a snapshot of the column "user_id":
I need to show the "name" part of the user. I tried using CONVERT and even JSON_VALUE but both are not recognized by Holistics.
I used CAST but still the user_id is in numerical form.
Here's the my code:
And here's the data output:
Can you help me on what to do to be able to show the actual name of the sales person?
I'm a newbie here and its my first post that's why all my snipshots are put in a link form.
To select a particular field from a JSON data (and JSON is what you have in user_id column), try this combination:
SELECT
JSON_UNQUOTE(JSON_EXTRACT(user_id,'$.id')) as id
JSON_UNQUOTE(JSON_EXTRACT(user_id,'$.name')) as user_name
FROM public.deals
This should return the user's id and name from your JSON column.
Whatever software you use, it probably expects the data to be retrieved in a row-column format, so you just need to play with the SQL query, so that it returns properly formatted data. And since you have JSONs in a user_id column (which seems weird, but nevermind) - a combination of JSON_EXTRACT, JSON_UNQUOTE and perhaps CAST should do the trick.
But bear in mind, that running DISTINCT on a big table using those methods could be slow.

One to Many - Calculated Column

I am trying to teach myself the new Tabular model for SQL 2012 SSAS to handle some analytic reports that were previously handled in (slow) stored procedures.
I've made decent progress on most of it, just figuring out how things work and how to add the calculations I need but I have been banging my head against the following:
I have a table that has file information -- it has:
ID
FileName
CurrentStatus
UploadedBy
And then a table that has statuses that the file went through (a many relationship to the file table):
FileID
StatusID
TimeStamp
What I'm trying to do is to add a calculated column to the File table that returns the TimeStamp information when a file was in a particular status. ie: StatusID=100 is uploaded. I want to add a calculated column called UploadedDate on the File table that has the associated TimeStamp information from the FileStatus table.
It seems like this should be doable with DAX but I just can't seem to wrap my head around it. Any ideas out there?
In advance, many thanks,
Brent
Here's a formula that should work for what you want to do...
=MAXX(
CALCULATETABLE(
'FileStatus'
,'FileStatus'[StatusID] = 100
)
,'FileStatus'[TimeStamp]
)
I'm assuming each file can only be in each status once (there is only one row per FileID that has StatusID 100). I believe you can just use a lookupvalue formula. The formula for your UploadedDate calculated column would be something like
=LOOKUPVALUE(FileStatus[Timestamp], File[FileID], FileStatus[FileID], FileStatus[StatusID], 100)
Here's the MSDN description of LOOKUPVALUE. You provide the column containing the value you want returned, the column you want to search, and the value you are searching for. You can add multiple criteria to your lookup table. Here's a blog post that contains a good example.