Group By & Aggregate: Pivot Table for Datasets avatar

Group By & Aggregate: Pivot Table for Datasets

Pricing

from $0.49 / 1,000 input rows

Go to Apify Store
Group By & Aggregate: Pivot Table for Datasets

Group By & Aggregate: Pivot Table for Datasets

Groups the rows of an Apify dataset or CSV/JSON files by one or more columns and computes count, sum, average, min, max, distinct count, first, last or median per group, with an optional pivot. Empty input runs a free demo.

Pricing

from $0.49 / 1,000 input rows

Rating

0.0

(0)

Developer

Actor Factory

Actor Factory

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

2 days ago

Last modified

Features

Limited permissions

Share

Group the rows of a dataset or CSV by one or more columns and get totals, averages, counts and more for each group, with an optional pivot table.

You scraped 80,000 product rows and want the average price per brand. You have an order export and want revenue per country and month. You want the top 10 categories by number of items. In a spreadsheet that is a pivot table; in SQL it is a GROUP BY. This Actor does it for Apify datasets and CSV / TSV / JSON / NDJSON files from the Console form, with no code and no spreadsheet row limit.

  • Cost: $0.70 per 1,000 input rows ($0.0007 per row) plus $0.0005 per run for the start. The $5 monthly free credit covers about 7,000 rows. The demo, failed runs and rows over your limit are free.
  • Try it free: clear the file URL field and press Start. A built-in sample of 12 orders is grouped by region (not charged, rows carry _demo: true).

What you get

Input: 12 orders (region, product, quarter, amount). Group by region, ignore case, aggregations orders = count, revenue = sum of amount, avg_order = avg of amount, biggest_order = max of amount, products = count_distinct of product, pivot on quarter (sum of amount), sorted by revenue, largest first:

regionordersrevenueavg_orderbiggest_orderproductsQ1Q2
North3604.5201.52673394.5210
East25222614202420102
West4397.499.352104257.4140
South3346115.331782178168
  • One output row per group. Your group-by columns come first, then one column per aggregation (named as you like), then one column per pivot value.
  • north and North fell into one group because spaces were trimmed and case was ignored.

What it does

  • Group by one or more columns. Up to 10, nested fields with dots (address.city). Leave it empty to get a single row with the totals of the whole table.
  • Nine aggregations. count, sum, avg, min, max, count_distinct, first, last, median. You name each output column and say which input column it is calculated from. Up to 30 aggregations per run.
  • Simple pivot. One column's values become output columns (quarters, countries, plans), each cell holding one aggregation, such as the sum of amount. Up to 1,000 pivot columns (default 100); more than that stops the run before anything is charged.
  • Sort and limit. Sort by any output column (numbers sort as numbers, empty values last), then keep the first N groups for a top list.
  • Forgiving values. Trim spaces (on by default, also full-width spaces) and ignore upper/lower case (off by default). 123, 123.0 and "123" are the same group; 00123 is not 123. An empty group value is its own group, shown as null.
  • Numbers from CSV text. In CSV files every value is text. sum, avg and median read "12.5", " 7 " and "1,234.50" as numbers and ignore values that are not numbers (the count is reported in the notes).
  • Several sources at once. One dataset plus up to 20 files, read as one table.
  • Big tables. Rows are streamed one by one; only the groups are kept in memory (up to 500,000 groups). median and count_distinct keep their values per group, so use them on fewer columns for very large inputs.

How to use

  1. Apify dataset and/or File URLs: the rows to group.
  2. Group by columns: for example country.
  3. Aggregations: a list of calculations. Each has a name, a field and a function:
{
"datasetId": "WkzbQMuFYuamGv3YF",
"groupBy": ["country", "category"],
"aggregations": [
{"name": "orders", "function": "count"},
{"name": "revenue", "field": "amount", "function": "sum"},
{"name": "avg_price", "field": "price", "function": "avg"},
{"name": "customers", "field": "email", "function": "count_distinct"}
],
"sortBy": "revenue",
"sortOrder": "desc",
"limit": 10
}

For a pivot add "pivotColumn": "month", "pivotField": "amount" and "pivotFunction": "sum".

The aggregations

functionneeds fieldresult
countnowith no field: the number of rows in the group. With a field: the rows where that field is not empty
sumyestotal of the numbers (null if there is no number)
avgyesaverage of the numbers
medianyesmiddle number (average of the two middle ones for an even count)
min / maxyessmallest / largest number; if the values are text, the first / last in alphabetical order
count_distinctyesnumber of different non-empty values (trimmed; case ignored if you chose so)
first / lastyesfirst / last non-empty value in input order

Empty values (null, empty text, spaces only) are skipped by every function except a field-less count.

Output

  • Dataset: one row per group, ready to download as CSV, Excel, JSON, XML or HTML. Group-by values are shown as they appear in the first row of the group (trimmed if trimming is on).
  • STATS record (key-value store): input rows read, number of groups, the output columns, rows charged, and notes (for example values ignored because they were not numbers, or a stop at your limit).
fieldmeaning
group-by columnsthe values that define the group
aggregation columnsone per aggregation, named by you
pivot columnsone per value of the pivot column
_demotrue on the free demo rows

Limits (cannot be raised by input)

  • Up to 10 group-by columns, 30 aggregations, 500,000 groups, 20 file URLs and 10,000,000 input rows per run (the default Max input rows is 1,000,000)
  • Files up to 100 MB each; JSON arrays up to 50 MB (use NDJSON for bigger files). Excel files are not read: save them as CSV first. Public links only (no login); addresses on internal networks are blocked
  • A source that cannot be read (wrong dataset ID, HTTP error, broken JSON), a column that no row has (a typo), a pivot with too many values or too many groups stops the run before anything is written or charged
  • Set a maximum cost per run to cap spend: the run reads as many rows as the limit pays for (after the start fee), stops cleanly (status Succeeded) and says so in the status message and STATS. The result then covers only the rows read.

Pricing

Pay per event: $0.0007 per input row ($0.70 per 1,000 rows) and $0.0005 per run. You pay for the rows read, not for the groups written, so a 1,000-row table costs $0.7005 whether it makes 3 groups or 300. The run fee is charged once, only when the run read at least one row and wrote its result, so a very small run still covers its start cost. The header row of a CSV is not counted. Failed runs, invalid input, rows over your limit and the demo are not charged. Store discounts apply automatically: BRONZE −10%, SILVER −20%, GOLD −30%. On the Apify Free plan, the $5 of monthly platform credit covers about 7,000 rows in one run.

FAQ

Is it the same as a pivot table? The pivot option gives the same layout for one row field (or several), one column field and one aggregation. For several different aggregations per column, list them under Aggregations instead.

Why is my sum empty (null)? None of the values in that group were numbers. In CSV files check the column for text like n/a or currency symbols; the STATS notes tell how many values were ignored.

Why did I get two groups that look the same? They differ in case (North and north) or in a character you cannot see. Turn on Ignore upper/lower case and Trim spaces.

Does the limit make the run cheaper? No. Limit only trims the output; every input row is still read and charged. To read fewer rows use Max input rows or filter the data first.

Does it work with datasets from other Actors' runs? Yes, any dataset your account can read. Paste the defaultDatasetId of a run or the dataset URL from Apify Console.

Can I group by two columns and pivot a third? Yes: list two group-by columns and set the pivot column. Each group row then gets one column per pivot value.

More tools from the same developer

  • Filter CSV, JSON or Dataset Rows by Condition — keep only the rows of a CSV, JSON file or dataset that match simple conditions like country = US or price > 100
  • Dataset Transform — flatten, filter, rename and convert any Apify dataset, export CSV / JSON / JSONL with a link
  • Transpose Table — swap the rows and columns of a CSV, JSON or dataset table
  • Join Datasets — join two datasets or CSV/JSON files on a key column (inner, left, right, outer or VLOOKUP-style)
  • Dataset Splitter — split a dataset or CSV/JSON file into parts by rows, parts, column value or size, or take a random sample