# Unique Field Values Summary

> Part of the NocoDB documentation (Workflows > Scripts > Examples). Index of all pages: https://nocodb.com/llms.txt. Any docs page is available as Markdown by adding `.md` to its URL.

URL: https://nocodb.com/docs/workflows/scripts/examples/unique-field-values-summary
Last updated: 2026-10-03

A NocoDB script that shows the unique values in a field and how often each occurs, as a summary and a table.

This script scans a field in your NocoDB table. It shows all **unique values** and how many times each value occurs. Use it to find duplicates, audit data or quickly see how the field values are distributed.

```javascript
// Prompt user to select a table and a field
let table = await input.tableAsync("Select a table");
let field = await input.fieldAsync("Select a field", table);

// Start query with pageSize
let queryResult = await table.selectRecordsAsync({
    fields: [field],
    pageSize: 100,
});

// Create a Map to store value -> count
let valueCounts = new Map();
let totalRecordsProcessed = 0;

// Helper function to process a batch of records
function processRecords(records) {
    totalRecordsProcessed += records.length;

    for (let record of records) {
        let value = record.getCellValue(field);

        // Normalize the value
        let normalizedValues = [];
        if (Array.isArray(value)) {
            normalizedValues = value.map(v => v?.name ?? v);
        } else if (value && typeof value === 'object') {
            normalizedValues = [value.name ?? JSON.stringify(value)];
        } else {
            normalizedValues = [value];
        }

        for (let val of normalizedValues) {
            let key = val === null ? "null" : String(val);
            valueCounts.set(key, (valueCounts.get(key) || 0) + 1);
        }
    }
}

// Process first page
processRecords(queryResult.records);

// Keep loading more pages if available
while (queryResult.hasMoreRecords) {
    await queryResult.loadMoreRecords();
    processRecords(queryResult.records.slice(-100)); // Only process newly loaded records
}

// Convert to array of objects for output.table()
let resultTable = Array.from(valueCounts.entries())
    .sort((a, b) => b[1] - a[1])
    .map(([value, count]) => ({
        Value: value,
        Count: count
    }));

output.markdown("### Unique Values with Counts");
output.table(resultTable);

// Output total number of records processed
output.markdown(`**Total records processed:** ${totalRecordsProcessed}`);
```

### Use Cases

* **Data Cleanup**: Find unexpected or duplicate values.
* **Analytics & Auditing**: See how often each value occurs in a field.
* **Form Design**: Find common values to use in selects or filters.
* **Debugging**: Review how a field behaves during imports or syncs.

### How It Works

1. **Select a Table and Field**.
2. **Script Scans All Records**: The script uses pagination.
3. **Normalizes All Values**: This includes arrays, objects, linked records and selects.
4. **Counts Frequency**: The script counts each unique value.
5. **Displays a Table**: The table shows the values and their counts.
6. **Prints Total Records Processed**: The total shows at the bottom.

### Benefits

* ✅ Works with all field types (for example, text, select and linked).
* ⚡ Fast and scalable: pagination lets it process thousands of records.
* 📊 The output is clean, sortable and easy to copy.
* 🔍 Shows common or inconsistent entries at once.
* 🧹 Helps with cleanup, analysis and automation planning.

---

## Related pages

- [API Reference Manual Examples](https://nocodb.com/docs/workflows/scripts/examples/api-ref-manual-examples.md): An index of the NocoDB Scripts API reference examples, grouped by category, for common scripting tasks.
- [Find and Replace](https://nocodb.com/docs/workflows/scripts/examples/find-and-replace.md): A NocoDB script that finds and replaces text in any text-based field across records, with a preview and a confirmation.
- [Convert Attachments to URLs](https://nocodb.com/docs/workflows/scripts/examples/convert-attachments-to-urls.md): A NocoDB script that converts attachment fields into comma-separated lists of URLs for external services.
- [Randomize Values](https://nocodb.com/docs/workflows/scripts/examples/randomize-values.md): A NocoDB script that fills empty fields with random data, for many field types, with ranges and constraints that you set.
- [Validate Emails](https://nocodb.com/docs/workflows/scripts/examples/validate-emails.md): A NocoDB script that finds and lists all invalid email addresses in email fields to check data quality.
- [Get Select Options](https://nocodb.com/docs/workflows/scripts/examples/select-options.md): A NocoDB script that lists all options of a Single Select or Multiple Select field in one of three formats.
- [Save View Ordering to Field](https://nocodb.com/docs/workflows/scripts/examples/save-view-ordering.md): A NocoDB script that saves the record order of a view as sequential numbers in a numeric field.
- [Link Records by Field](https://nocodb.com/docs/workflows/scripts/examples/link-records-by-field.md): A NocoDB script that links records in two tables by matching field values, with pagination and a summary report.
