# Dataset Merge, Dedupe & Transform - Apify Datasets (`pshivam/dataset-merge-dedupe`) Actor

Merge Apify datasets into one: remove duplicates by any fields, filter records, sort, pick, rename or flatten fields. Keeps the first or the last duplicate. Streams large datasets. Export to Excel, CSV or API.

- **URL**: https://apify.com/pshivam/dataset-merge-dedupe.md
- **Developed by:** [Shivam Prajapati](https://apify.com/pshivam) (community)
- **Categories:** Automation, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Dataset Merge, Dedupe & Transform - Apify Datasets

**Merge Apify datasets into one clean dataset: remove duplicates by any fields, filter records, sort, pick, rename or flatten fields.** Give the ids of your datasets (for example the results of several runs of a scraper), say which fields identify a record, and get one deduplicated dataset you can export to Excel, CSV, JSON or the API. No code.

**Actively maintained.** Last update: 2026-11-21. Every release passes 100+ automated tests, including merges of 25,000 records.

### What can you use it for?

- **Join the results of many runs.** A scraper run every day or by city: one dataset of all of them.
- **Remove duplicates.** The same product, lead or listing found by several searches: keep one, by URL, email, ID or any set of fields.
- **Keep the newest record.** List the oldest dataset first, choose to keep the last duplicate, and the newest version of each record wins.
- **Clean a dataset for a CRM or a sheet.** Keep only the fields you need, rename them, drop test records with a filter.
- **Sort and cut.** The 100 cheapest items of 20 runs, or the leads of one country.
- **Combine different scrapers' output.** Rename their fields to the same names and flatten the nested ones.

### How does it work?

The Actor reads your datasets in the order you give, one record at a time, and applies the options in this order:

1. **Flatten** nested objects (optional).
2. **Filters**: records that fail a condition are left out.
3. **Duplicates**: records with the same values in the fields you chose (or identical records) are removed, keeping the first or the last.
4. **Sort** (optional).
5. **Fields**: keep, drop, rename.
6. **Return** the records.

Without sorting and without 'keep the last', records are returned as they are read, so the datasets can be much bigger than the memory of the run.

#### Example result

Run with no input to see it: it merges three small example datasets of customers and removes the duplicates by email (the same person with different capital letters and spaces). The first two records:

```json
[
  {
    "id": 1,
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "country": "UK",
    "orders": 12,
    "address": {
      "city": "London"
    }
  },
  {
    "id": 2,
    "name": "Grace Hopper",
    "email": "GRACE@example.com",
    "country": "US",
    "orders": 7,
    "address": {
      "city": "New York"
    }
  }
]
```

#### Fields

The records have the fields of your datasets. The Actor adds only these, and only if you turn on `addSourceFields`:

##### Source

| Field | What it is |
|---|---|
| `_sourceDatasetId` | Only with 'Add source fields': the id of the dataset the record came from. |
| `_sourceIndex` | Only with 'Add source fields': the position of that dataset in your list, starting at 0. |

### Input

| Input | What it does |
|---|---|
| `datasetIds` | The datasets to merge, in order |
| `dedupeBy`, `dedupeIdentical`, `keep`, `ignoreCase` | Which fields make a record unique, which duplicate to keep, whether case matters |
| `filters` | Conditions a record must pass: ==, !=, >, >=, <, <=, contains, startsWith, in, exists, matches ... |
| `includeFields`, `excludeFields`, `renameFields`, `flattenObjects` | Pick, drop, rename and flatten fields |
| `sortBy`, `sortOrder` | Sort the result |
| `addSourceFields` | Add where each record came from |
| `maxItemsPerDataset`, `maxItems` | Limits |
| `onlyNew` | Skip records that earlier runs of the same input returned |

### How much does it cost?

You pay per record returned. Records that you remove (duplicates, filtered, left out) are not returned and not charged. There is no start fee.

| Plan | Price per 1,000 records |
|---|---|
| Free | $0.50 |
| Bronze | $0.45 |
| Silver | $0.40 |
| Gold | $0.35 |

- Merging 100,000 records into 60,000 costs about $30 on the Free plan.
- Use `maxItems` to cap the cost of a run.

### Use it via API, on a schedule, or with your tools

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_API_TOKEN>")
run = client.actor("pshivam/dataset-merge-dedupe").call(run_input={
    "datasetIds": ["Hq4ZuqOHRPlCXXjla", "pshivam~my-other-data"],
    "dedupeBy": ["url"],
    "keep": "last",
    "filters": [{"field": "price", "op": ">", "value": 0}],
    "sortBy": "price",
})
for record in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(record)
```

#### Use it in Clay, n8n, Make or Zapier

Use the Actor ID `pshivam/dataset-merge-dedupe` and an input like this, for example after each scraper run:

```json
{"datasetIds": ["<DATASET_ID_OF_THE_RUN>"], "dedupeBy": ["email"], "includeFields": ["name", "email", "company"]}
```

### Good to know

- **Full permissions.** To read any dataset you list, the Actor runs with the full permissions of your account: it needs them to open datasets by id. It only reads the datasets you name and writes its own result. A dataset of another account must be shared with you. If a dataset cannot be read the run's status message says so and the other datasets are still merged. The example run without datasets needs no access.
- **Order matters.** Datasets are read in the order of the list, so the first duplicate is the one from the first dataset. List the oldest dataset first and choose `keep` last to keep the newest.
- **Records without the key are kept.** A record that lacks a field of `dedupeBy`, or has it empty, is never a duplicate.
- **Memory.** Streaming merges use little memory. Sorting, or keeping the last duplicate, holds the records in memory: 1 million small records need about 2 GB, so raise the memory of the run for big sorts.
- **Records are returned as they are.** Numbers stay numbers, nested objects stay nested (unless you flatten), nothing is converted.
- **Speed.** The merge itself runs at about 20,000 records a second. 100,000 records take under 30 seconds with most of the time spent reading the datasets from Apify.
- **Independent tool.** Not affiliated with Apify. It works on the datasets you give it and does not change them.

### FAQ

#### How do I merge two Apify datasets?

Put both dataset ids in `datasetIds` and run. The new dataset has the records of the first, then the second.

#### How do I remove duplicates?

Put the fields that identify a record in `dedupeBy` (url, email, id). Two records with the same values there are duplicates. Use `dedupeIdentical` when you have no such field.

#### How do I keep the newest record of each duplicate group?

List the oldest dataset first and set `keep` to last. The last record of each group wins.

#### Can I filter or sort the records?

Yes. `filters` keeps the records that pass every condition, and `sortBy` sorts them. Numbers inside text, like "49.50", are compared as numbers.

#### Does it change my original datasets?

No. It reads them and writes a new dataset.

#### Can it merge datasets of different scrapers?

Yes. Rename the fields to the same names with `renameFields` and flatten nested objects with `flattenObjects`.

# Actor input Schema

## `datasetIds` (type: `array`):

The datasets to merge, in order. Each entry is a dataset id, username~name or a link to the dataset in the Console (the dataset of an Actor run: Storage > Dataset). The datasets must be yours or shared with you. Leave empty to merge three small example datasets.

## `dedupeBy` (type: `array`):

The fields that make a record unique, one per line: email, url, seller.name (a field of an object), tags.0 (the first item of a list). Two records with the same values in all these fields are duplicates. Spaces and capital letters are ignored (see 'Ignore case'). A record that lacks one of the fields is kept. Leave empty to keep every record.

## `dedupeIdentical` (type: `boolean`):

Also remove records that are exactly the same in every field. Use it when you have no field that identifies a record.

## `keep` (type: `string`):

From each group of duplicates: the first record in the order of your datasets, or the last. The last needs all records in memory before the first is returned.

## `ignoreCase` (type: `boolean`):

Compare text without regard to capital letters and extra spaces, for the duplicates and the filters. Turn it off to compare exactly.

## `filters` (type: `array`):

Keep only the records that pass every condition. A list of objects: \[{"field": "price", "op": ">=", "value": 10}, {"field": "seller.country", "op": "in", "value": \["US", "UK"]}]. Operators: ==, !=, >, >=, <, <=, contains, notContains, startsWith, endsWith, in, notIn, exists, notExists, matches. exists and notExists need no value. Numbers in text ("49.50") are compared as numbers.

## `includeFields` (type: `array`):

Return only these fields of each record, one per line (seller.name is a field of an object). Leave empty to keep all fields.

## `excludeFields` (type: `array`):

Remove these fields from each record.

## `renameFields` (type: `object`):

Rename fields: {"sku": "id", "title": "name"}. Applied last.

## `flattenObjects` (type: `boolean`):

Turn nested objects into one level of fields with dotted names: {"seller": {"name": "Acme"}} becomes "seller.name": "Acme". All the other options then use these names.

## `sortBy` (type: `string`):

Sort the records by this field. Numbers (also in text) sort as numbers, text without regard to case, records without the field come last. Sorting needs all records in memory.

## `sortOrder` (type: `string`):

Ascending or descending.

## `addSourceFields` (type: `boolean`):

Add \_sourceDatasetId and \_sourceIndex to each record: where it came from.

## `maxItemsPerDataset` (type: `integer`):

Read at most this many records of each dataset. Leave empty to read all.

## `maxItems` (type: `integer`):

Stop after returning this many records. You are charged per record returned.

## `onlyNew` (type: `boolean`):

Skip records that earlier runs of this same input already returned, so you get and pay for new ones only. The first run works as usual and remembers what it returned, in your key-value store 'dataset-merge-dedupe-only-new'.

## Actor input object example

```json
{
  "dedupeBy": [
    "email"
  ],
  "dedupeIdentical": false,
  "keep": "first",
  "ignoreCase": true,
  "flattenObjects": false,
  "sortOrder": "asc",
  "addSourceFields": false,
  "maxItems": 1000,
  "onlyNew": false
}
```

# Actor output Schema

## `records` (type: `string`):

Records as a table.

## `runStats` (type: `string`):

Requests made, time spent and number of records for this run (RUN_STATS record).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "dedupeBy": [
        "email"
    ],
    "maxItems": 1000
};

// Run the Actor and wait for it to finish
const run = await client.actor("pshivam/dataset-merge-dedupe").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "dedupeBy": ["email"],
    "maxItems": 1000,
}

# Run the Actor and wait for it to finish
run = client.actor("pshivam/dataset-merge-dedupe").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "dedupeBy": [
    "email"
  ],
  "maxItems": 1000
}' |
apify call pshivam/dataset-merge-dedupe --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,pshivam/dataset-merge-dedupe"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/v36qGFJILp0g82n1t/builds/9jHJeBOODDmGiGWh7/openapi.json
