Sub topic 8
Rows, columns and pivoting your data
This chapter assumes you can open a Free-form exploration, that you have already imported dimensions and metrics into the Variables panel, and that you know the difference between event, session and user scopes. Here you will use the Tab Settings panel to arrange those fields into a pivoted table.
What rows and columns do
In a Free-form exploration, the table is built from four drop zones in Tab Settings: Rows, Columns, Values and Filters. This chapter covers the first two.
- Rows hold dimensions that run down the left side of the table. Each unique value, or combination of values, becomes one row.
- Columns hold dimensions that run across the top. Each unique value becomes a column group, and every metric in Values is repeated beneath it.
- Values hold the metrics that fill the cells.
Without a dimension in Columns, the table is flat. It has one row per dimension combination and one column per metric. With a dimension in Columns, the table is pivoted. The metrics are split across the column dimension's values.
| Layout | Rows | Columns | Result |
|---|---|---|---|
| Flat | Channel group | (none) | One row per channel, one column per metric |
| Nested rows | Channel group, then Device category | (none) | Each channel has child rows per device |
| Pivoted | Channel group | Device category | Each device is a column group, with metrics under it |
Build a pivoted table step by step
This example answers the question "How do sessions and engaged sessions differ by channel and device?"
- In the Variables panel, import the dimensions Session default channel group and Device category. Import the metrics Sessions and Engaged sessions.
- In Tab Settings, drag Session default channel group into Rows.
- Drag Device category into Columns.
- Drag Sessions and Engaged sessions into Values. You can also double-click a variable to add it to the next suitable drop zone.
- Check the date range at the top of the Variables panel, then review the table.
The result has one row per channel. Above the metric headers you see one group per device category, such as desktop, mobile and tablet. Each group repeats both metrics.
Nested rows and drill-down
You can put more than one dimension in Rows. The order matters. The first dimension is the outer level, and the second is nested inside it.
If Rows contains Session default channel group and then Device category, you see each channel with its device breakdown beneath it. If you swap the order, you see each device with its channels beneath it. The data is the same, but the grouping changes which comparison is easy to read.
Rows that contain nested dimensions can be collapsed or expanded. Use the arrow next to a row label to expand it. In the Tab Settings panel, the Nested rows setting controls whether child rows are shown. Set it to Yes to show them as indented rows. Set it to No to flatten every combination into a single level.
You can also set Start row and Show rows. Start row is the first row displayed, and Show rows is how many appear at once. The maximum is 250 rows per page. These settings control display only. They do not change which rows exist in the data.
Choosing between rows and columns
Both zones accept dimensions, so the choice is about readability and table size. Use these rules.
- Put the dimension with many values in Rows. Pages, landing pages, cities and campaigns can have hundreds of values. A table can scroll down comfortably, but wide tables are hard to read.
- Put the dimension with few values in Columns. Device category, new versus returning users and a small set of segments work well.
- Put the dimension you want to compare side by side in Columns. This lets you read across a row to compare the groups.
The Show rows and Show columns settings limit what appears. For columns, the pivot offers Columns per page and Start column. If a column dimension has more than the allowed number of values, only some are shown. Narrow the data with a filter if a value you need is missing.
Pivoting an existing table
You do not need to rebuild a table to change its layout. Drag a dimension from Rows to Columns, or the reverse, and the table recomputes. Dragging within the same zone reorders it.
The Cell type and Visualization choices are covered in later chapters. Be aware that some visualizations use rows and columns differently. A scatter plot, for example, ignores the Columns zone. If you switch visualization and your table seems to lose a dimension, check which zones that visualization reads.
Sorting
Click a metric header to sort rows by that metric. Click again to reverse the order. In a pivoted table, sorting uses the metric under one specific column group. You cannot sort by the combined total across all column values unless you enable totals.
If you sort by a metric, the sort applies to the outermost row dimension first. Nested child rows are sorted within their parent. A parent row's position depends on its own total, not on its largest child.
Totals and subtotals
Tab Settings includes options such as Show totals and Subtotals. These control whether the table adds a total row and a total column. Use them carefully, because not every metric adds up.
- Sessions and Event count are additive across channels, so a total row is meaningful.
- Total users and Active users count unique people. A user who visits on both mobile and desktop appears in both device columns. The grand total does not equal the sum of the parts. GA4 calculates the total from the deduplicated users, so the sum of the columns can be larger than the total.
- Rates and averages, such as engagement rate, are recalculated for the total. They are not summed.
This is a common source of confusion. If your column values for users do not add up to the total, the explanation is overlap between groups, not an error.
Field compatibility in pivots
The dimensions in Rows and Columns must be compatible with the metrics in Values. In the Variables panel, incompatible fields appear greyed out when you have already selected others. The reason is scope. A session-scoped metric such as Sessions works with Session default channel group. It does not work with an event-scoped dimension such as Event name. When a pivot would mix them, GA4 will not let you drag the field in, or it shows a warning.
If a dimension you need is greyed out, check which metrics and dimensions are already in use. Remove the one that conflicts, or choose a dimension with a matching scope. For example, use Session source / medium instead of First user source / medium if the metric is session-scoped.
Equivalent API request
The pivoted table above corresponds to a Data API runReport request. In the API, dimensions listed in one array are not split into rows and columns. The API returns a flat list of rows. You pivot the output in your own code, or use runPivotReport.
{
"dateRanges": [{ "startDate": "28daysAgo", "endDate": "yesterday" }],
"dimensions": [
{ "name": "sessionDefaultChannelGroup" },
{ "name": "deviceCategory" }
],
"metrics": [
{ "name": "sessions" },
{ "name": "engagedSessions" }
],
"limit": 25
}The limit value of 25 plays a role like the row-count display setting. It caps how many rows come back.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| A field cannot be dropped into a zone | Scope mismatch with a metric already in Values | Choose a field with matching scope, or remove the conflicting metric |
| The table is very wide | A high-cardinality dimension is in Columns | Move it to Rows, or filter to the values you need |
| Totals look too small | Unique-user metrics overlap across groups | Treat the total as the deduplicated count |
| Rows are missing | Show rows is set low, or a filter is active | Raise Show rows and check the Filters zone |
| Numbers differ from a standard report | Different date range, filters or thresholds | Match the date range and check for a data threshold icon |
Practical guidance
- Start with one row dimension and one metric. Add complexity one field at a time, so you can see which addition changed the table.
- Change one thing between views. If you swap a dimension and add a filter together, you cannot tell which caused a change.
- Name the tab for the question it answers, such as "Sessions by channel and device".
Exercise
A table has Session default channel group in Rows, Device category in Columns, and Total users in Values. The mobile column shows 4,000 users, the desktop column shows 6,000, and the grand total shows 9,200. Why does the total differ from 10,000, and where should you place a dimension that has 300 distinct values?
Show answer
Total users counts unique people. Some people used both mobile and desktop, so they are counted in both columns but only once in the grand total. The 800 difference is the overlap. A dimension with 300 values belongs in Rows, because a table scrolls vertically more readily than it fits across the page, and Columns is better for dimensions with a few values.
Exercise
You want each device category to be a column group above both Sessions and Engaged sessions, with one row per channel. Which dimension goes in which zone, and which metrics go where?
Show answer
Put Session default channel group in Rows, Device category in Columns, and both Sessions and Engaged sessions in Values.