Lompat ke konten

Pelajaran 11 ยท Grouping and Aggregation

Pivot Tables

Build Sigma pivot tables with pivot rows, pivot columns and values, control totals, format cells, and decide when a grouped table or a chart is better.

A pivot table turns a long list into a cross-table: categories down the side, other categories across the top, and a calculated value in each cell. It is a good fit for questions like "revenue by region and quarter".

The three areas

Sigma's pivot table has:

  • Pivot rows: one or more columns that become row headings.
  • Pivot columns: optional columns that split values across the top (when you already have at least one pivot row).
  • Values: the calculations shown in each cell.

The documentation says the pivot shows no data until you add at least one pivot row or pivot column. Numeric values default to a sum, and text and date values default to a count. Check the aggregate and change it if needed.

TEXT
Pivot rows:     Region
Pivot columns:  DateTrunc("quarter", [Order Date])
Values:         Sum([Revenue])
                CountDistinct([Order ID])

When you add a second pivot row, you can show the levels in one stepped column or in separate columns. You can also swap rows and columns, and move the Values area to change how the headings nest.

SQL Stand-in: a cross-table built with conditional sums

Press Run (or Ctrl + Enter) to see the result here.

Look at West in Q1. There are no sales, so the cell is empty (null), not zero. In a real report decide what an empty cell means: no sales, or data not loaded yet?

Totals and subtotals

By default, subtotals appear for the immediate parent row. You can change this so subtotals show at every parent level. Grand totals appear at the bottom. You can format totals, and conditional formatting can target values, subtotals or grand totals.

A total is calculated with an aggregate, so check what each total means. For a ratio value, a good total is the ratio of the totals, not a sum or an average of the ratios.

Shares inside a pivot

Use PercentOfTotal with pivot modes to show shares:

TEXT
PercentOfTotal(Sum([Revenue]), "column")   share within each column
PercentOfTotal(Sum([Revenue]), "row")      share within each row

Read the previous lesson for the other modes.

Pivot or grouped table?

Situation Better choice
Compare a measure across two dimensions Pivot table
Drill from summary to individual rows Grouped table
Many measures per group Grouped table
Time across the top for reading trends Pivot table or chart
Hundreds of columns across the top Probably neither: filter or chart it

A pivot with a high-cardinality column (one with very many distinct values) across the top, such as customer name, becomes unreadable. Filter first, or move that dimension to the rows.

Permissions and exploring

According to the documentation, creating or editing a pivot table needs Can edit access to the workbook, while some exploration actions work with Can explore. If a colleague cannot rearrange your pivot, check both their account type and their document access.

Conditional formatting

Color can help a reader spot patterns, for example a color scale on revenue or a rule that highlights negative margins. Use it with care:

  • Do not rely on color alone; keep the numbers visible and use clear labels.
  • Pick colors that remain readable for people with color vision differences.
  • Do not mix totals into a color scale, or they will dominate it.
Python Stand-in: pivot from long rows to a grid in Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The dash shows a missing combination clearly instead of inventing a zero.

Design tips

  • Put the dimension with fewer values across the top.
  • Sort rows by the value readers care about.
  • Use consistent decimals and units, and say "USD thousands" if you shorten numbers.
  • Limit the number of measures; two or three are usually readable.
  • Add a short text element that states what the pivot answers.

Common mistake: reading a pivot of averages as if its totals were averages of the visible cells. A total is usually computed from the underlying rows, so it may not match a mental average of the cells. Explain this to readers.

Check your work

Compare one cell with a grouped table that has the same two dimensions, and compare the grand total with the source total. If they differ, look for filters, null values in a pivot dimension and duplicate rows from joins.

A worked reading

Suppose a pivot shows return rates by product family in the rows and by sales channel across the top. One cell shows a very high rate. Before you act on it, look at the volume behind it.

Add a second value that counts sold items, so each cell shows both the rate and the base. A high rate from three sales is mostly noise, while a moderate rate from many thousands of sales may deserve attention. Next, check the totals. The family total should come from all returns divided by all sales in that family, not from a simple average across channels.

Then drill into the cell, or build a grouped table with the same filters, and look at the individual returns. You may find one defective batch, a data entry problem or a single large customer.

Finally, record what you did. Note the filters, the period and the definition of a return. A pivot is a starting point for questions, and these notes let another person repeat your steps and reach the same cell.

Ask a colleague to read the pivot without your help, and watch which headings confuse them.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What must a pivot table have before it shows data?

    The documentation says no data appears until a pivot row or column is added.
  2. 2. What is the default aggregation for numeric values?

    Numbers default to Sum and text or dates to Count, and you can change this.
  3. 3. When is a grouped table better than a pivot?

    Grouped tables keep the detail rows within reach.
  4. 4. What should you do about an empty cell in a pivot?

    An empty cell and a true zero can mean very different things.

Summary

  • Pivot tables use pivot rows, optional pivot columns and values.
  • Check default aggregates and what totals compute.
  • Use percentage modes to show shares by row or column.
  • Choose a grouped table when readers need row detail.
  • Treat empty cells carefully and verify totals.

Next: Joins and Unions

Progres Anda disimpan di browser ini. Tidak perlu akun.