In my previous post I wrote about the process that lead me to build a dashboard but first I want to talk a bit about the structure of the data in the Google Sheet where the whole process started. I first started by looking to quickly create a few charts to visualize some of our KPI‘s. To source the data I created a text file containing the SQL statements and used psql to fetch Postgres data which I dumped it to data into .CSV files for import into separate “data” only tabs in Google Sheets.
psql -h pgserver -d mydb -U myuser -w -t -A -F
&lt;img src=”data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ data-wp-more=”more” data-wp-more-text=”” class=”wp-more-tag mce-wp-more” alt=”” title=”Read more…” data-mce-resize=”false” data-mce-placeholder=”1″ /&gt;
The first tab was the “primary” dataset which contained a wide (A to AX) set of columns with a blend of content from the various linked “data” tabs and is where I derived all of the pivot tables with a primary key in the first column and with this initial set of at I was able to start building charts to help visualize the data.
&lt;img class=”size-full wp-image-2161″ src=”http://lh3.googleusercontent.com/NP6GKDudocLGJBcRHuPVKW4Xcri2S-xbhtaGhArKUMBTz-fZF5qwUjVXa2wiATAC5rvELjL6hSN9hGuMlyISRGKYbz2U=s0″ alt=”gsheet”&gt;
&lt;a href=”https://www.stevetrefethen.com/wp-content/uploads/2016/07/220px-Recycling_symbol.svg_.png”&gt;&lt;img class=”alignright wp-image-2156″ src=”https://www.stevetrefethen.com/wp-content/uploads/2016/07/220px-Recycling_symbol.svg_.png” alt=”220px-Recycling_symbol.svg” width=”81″ height=”81″&gt;&lt;/a&gt;Of course, once you’ve answered one question it leads to follow-on questions which require more data leading to more questions. Before long I was querying a dozen tables from Postgres and MSSQL and importing the data into these “data” tabs. For data tabs with a 1-1 relationship based on primary key I would &lt;a href=”https://support.google.com/docs/answer/75943?hl=en”&gt;aggregate the data onto the main sheet&lt;/a&gt;&amp;nbsp;with a formula like &lt;em&gt;=”Imported Data’!B4&lt;/em&gt;&amp;nbsp;or in cases where not all keys were present via a lookup like&amp;nbsp;&lt;em&gt;=IFERROR(VLOOKUP($A:$A,”Data Sheet”!$A:$E,3,FALSE),0)&lt;/em&gt; setting the result accordingly when the primary key wasn’t found.
Ultimately, flattening the data made it easy to construct pivot tables for aggregate totals, averages, counts, and median values etc. from which I could build a variety of charts a sampling of which I’ve included below.
Here’s a small sample of the kinds of charts built from pivot tables. Yes, I’ve clipped/changed some of the legends knowingly obscuring the underlying meaning of the chart.
&lt;td&gt;&lt;a href=”https://www.stevetrefethen.com/wp-content/uploads/2016/07/monthlytotals.png”&gt;&lt;img class=”alignnone wp-image-2157″ src=”http://lh3.googleusercontent.com/IsGZy68uhIxRVGYGj7UpqgRRNjwEjseg4UCJSR6CUSQcJokDcLdy5fwisof8iKg0we3MLcAqjXL2wENoeSGGOA4NBIA1=s1024″ alt=”Monthly Totals” width=”523″ height=”316″&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;img class=”wp-image-2159″ src=”http://lh3.googleusercontent.com/yFrnpS-yHhyXen6LazKPcWkKYExpMTFL9u60a6u2EVpC3mJqRht0kDj1Jh57F5u5jYHM4h-zVLZtihKkxCxfazpudplO=s0″ alt=”typeusage” width=”556″ height=”302″&gt;&lt;/td&gt;
I built a variety of pivot tables for the Wanderful Marketing team (sans charts) for easy analysis of Cash Dash campaigns from a variety of angles such as by a given retailer by offer type, amount, reward, launch day of the week and a variety of campaign performance metrics that I’d calculated within the sheet. Ultimately, the usefulness of this data caught on and a number of teams were not only reviewing the data but asking for additional analysis and updates.
While I was able to automate some portions of updating this sheet, its associated tabs etc. Google Sheet’s charts and pivot tables don’t automatically expand as the size of your data grows which made it a laborious task to “re-scope” them as more data was added not to mention I knew the 2M cell limit was looming in the distance.
In a follow-on post I’ll talk about how I began the shift to automating this using R and a Shiny Dashboard running on an OSX Mac mini.
\t’ &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;-f ~/Campaigns.sql &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; campaign.csv
Continue reading Using Google Sheets, Pivot Tables and Charts as a Startup Dashboard – Part II