When you want to combine two or more queries, such as multiple Google Analytics segments, the Analytics Edge Core Add-in provides the tools to automate it. In a simple scenario, let’s make a quick table showing top-level metrics like Users and Sessions for each of several segments.
Building the Queries
We start with the individual queries — the current release of the Google Analytics connector requires separate queries for each segment. Creating a query with the metrics you want is straightforward — pick the account and view, the segment, add the fields, and pick a date range (see Your First Query). Notice that there is no “Segment” column in the results — this will need to be added.
To add a Segment column with an appropriate label, you use the Arrange function to Insert a column. Insert the column Before column A (select the first row in the list of columns), with a New Column Name of “Segment” and an Initial Text Value appropriate to the segment you have used in your query (“All Users” in this case).
Before we move on to the next query, set a bookmark to these results so we can reference them later in the macro. Use the Table Name function to Assign a name to the current table with something appropriate, like “All Users“.
Repeat for the other segments you want in your results, making the query, inserting a “Segment” column and naming the table.
Combining the Results
Analytics Edge offers a number of ways to combine multiple tables of data, but in this case, we want to simply Append each row to a common table. Start by Switching to the first saved Table Name: “All Users“.
Then we use the Append function to append each of the other tables to the one we are working with. The Append function adds the referenced data to the bottom of the current table, aligning the column names so the various metrics are automatically aligned properly from row-to-row.
Note that if your data required appending new columns to your existing rows (instead of new rows to existing columns as in the example shown), you would use the Combine function instead of the Append function (see Using the Combine Function).
End your macro by writing the results to your desired worksheet location with the Write Worksheet function.
Summary
The Analytics Edge Core Add-in can be used to transform any combination of queries and data sets into named tables, which are then easily merged into a single table for your report.
Start with your queries, adding a label column if necessary, then assign table names to the results. Finish off by using the Append or Combine functions to bring all the tables together before writing to your worksheet.