1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "data": [
12 {
13 "orderId": 1001,
14 "region": "North",
15 "product": "Widget",
16 "amount": "$1,200.00",
17 "orderedAt": "2026-07-03"
18 },
19 {
20 "orderId": 1002,
21 "region": "North",
22 "product": "Gadget",
23 "amount": 350,
24 "orderedAt": "2026-07-18"
25 },
26 {
27 "orderId": 1003,
28 "region": "South",
29 "product": "Widget",
30 "amount": "890.50",
31 "orderedAt": "2026-07-22"
32 },
33 {
34 "orderId": 1004,
35 "region": "south",
36 "product": "Gizmo",
37 "amount": 120,
38 "orderedAt": "2026-08-02"
39 },
40 {
41 "orderId": 1005,
42 "region": "East",
43 "product": "Widget",
44 "amount": 2400,
45 "orderedAt": "2026-08-05"
46 },
47 {
48 "orderId": 1006,
49 "region": "East",
50 "product": "Gadget",
51 "amount": "n/a",
52 "orderedAt": "2026-08-09"
53 },
54 {
55 "orderId": 1007,
56 "region": "North",
57 "product": "Gizmo",
58 "amount": 75,
59 "orderedAt": "2026-08-11"
60 },
61 {
62 "orderId": 1008,
63 "region": "",
64 "product": "Widget",
65 "amount": 410,
66 "orderedAt": "2026-08-14"
67 }
68 ],
69 "groupByFields": [
70 "region"
71 ],
72 "aggregations": [
73 {
74 "function": "count",
75 "alias": "orders"
76 },
77 {
78 "field": "amount",
79 "function": "sum",
80 "alias": "total_amount"
81 },
82 {
83 "field": "amount",
84 "function": "avg",
85 "alias": "avg_amount"
86 }
87 ],
88 "exportFormats": [
89 "csv",
90 "xlsx"
91 ]
92};
93
94
95const run = await client.actor("nerolabs/dataset-aggregate-pivot").call(input);
96
97
98console.log('Results from dataset');
99console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
100const { items } = await client.dataset(run.defaultDatasetId).listItems();
101items.forEach((item) => {
102 console.dir(item);
103});
104
105