Im currently processing data in BigQuery then export into Excel to do the final Pivot table and was hoping to be able to create the same with the PIVOT option in BigQuery.
My Data set in big query looks like
Transaction_Month || ConsumerId || CUST_createdMonth
01/01/2015 || 1 || 01/01/2015
01/01/2015 || 1 || 01/01/2015
01/02/2015 || 1 || 01/01/2015
01/01/2015 || 2 || 01/01/2015
01/02/2015 || 3 || 01/02/2015
01/02/2015 || 4 || 01/02/2015
01/02/2015 || 5 || 01/02/2015
01/03/2015 || 5 || 01/02/2015
01/03/2015 || 6 || 01/03/2015
01/04/2015 || 6 || 01/03/2015
01/06/2015 || 6 || 01/03/2015
01/03/2015 || 7 || 01/03/2015
01/04/2015 || 8 || 01/04/2015
01/05/2015 || 8 || 01/04/2015
01/04/2015 || 9 || 01/04/2015
It is essentially an order table with customer information appended.
When i put this data into excel I add it to a pivot table, I add the CUST_createdMonth as a Row, Transaction_Month as a column and the value is a distinct Count of the ConsumerID
Is this sort of pivot possible in BigQuery?
Actually Mikhail there is another way to transpose rows of an EAV type schema into columns, by using logging tables and querying the last CREATE TABLE entry to determine the latest table schema.
There is no nice way of doing this in BigQuery, but you can do it follow below idea
Run below query
As a result - you will get string like below (it is formatted below for readability sake)
Just run above composed query
Result will be lik e below
Step 1 is helpful if you have many months to pivot so too much of manual work.
In this case - Step 1 helps you to generate your query
How to scale Pivoting in BigQuery?
Please note – there is a limitation of 10K columns per table - so you are limited with 10K organizations.
You can also see below as simplified examples (if above one is too complex/verbose):
How to transpose rows to columns with large amount of the data in BigQuery/SQL?
How to create dummy variable columns for thousands of categories in Google BigQuery?
Pivot Repeated fields in BigQuery