Sql – How to GROUP BY a column/s in data studio

google-bigquerygoogle-data-studiosql

I have a sales table with the purchase history of multiple customers. Needless to say a single customer can appear multiple times in the table. I need to group by the customers and do a count of the industries each customer works in and visualize it in a table in data studio. I need to do all of this in data studio itself.

In big query the syntax would look something like this:

SELECT Industry, count(industry) AS industry_count 
FROM (SELECT 
    CustomerID, 
    Industry 
    FROM `project1.pr.df_full` 
    WHERE  segment = 'Lost'
    GROUP BY CustomerID, Industry)
GROUP BY Industry
ORDER BY industry_count DESC

How can I achieve the same thing in data studio? The WHERE clause doesn't have to be there because I have a segment filter on the page I'm trying to do this on

Best Answer

As I said in the comment, I reproduced your query and it worked fine. Here you can see a guide about how to connect BigQuery to DataStudio

Please, notice that DataStudio have some limitations in the query syntax:

enter image description here

If you need further information, please let me know