Shape · Summarize and reshape

Group Aggregate

Works out a group total and writes it onto every row instead of collapsing them, as the value, a ratio or a percent. For example, each sale as a share of its region's total.

Also known as: Percent of total, window total

How it works

Pick the Group by columns, or none for a grand total over all rows, the Column to total and a Function: Sum, Count, Average, Min, Max, Median or Std dev. Mode decides what is written: Value puts the group total on each row, Ratio (share of group) divides the row's value by the total to give a 0 to 1 fraction, % of group gives that times 100. A group whose total is 0 gives null in the ratio and percent modes. The row count never changes. Output column defaults to SUM_amount, amount_ratio or amount_pct depending on the mode. To collapse rows instead, use Aggregate.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Group Aggregate, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  groupBy?: string[]
  column: string
  func: "SUM"|"COUNT"|"AVG"|"MIN"|"MAX"|"MEDIAN"|"STDDEV"
  mode: "value"|"ratio"|"pct" ("ratio" = column / group total as a 0-1 fraction — the one to format as a percent; "pct" = 100 × that ratio, 0-100 percent points)
  outputColumn?: string
}

Example

Each sale should show its share of its region's revenue. Group by region, pick amount, Sum and Ratio (share of group), then format amount_ratio as a percent in Format Table.

regionamountamount_ratio
North3000.75
North1000.25
South501.0