Skip to main content

Merge Rows in Excel in Power Automate

PDF4me Merge Rows is a Power Automate action that groups duplicate Excel rows by one or more key columns and combines the remaining values into a single consolidated row. Use it to collapse repeated customer, category, or transaction entries into one row per key, or leave the key columns blank to remove exact duplicate rows outright.

What this action does

PDF4me Merge Rows reads an Excel file plus a set of key column numbers, groups rows that share the same key values, and joins the non-key values from each group with a semicolon separator after removing duplicate values within that group. Rows that share every column value are treated as exact duplicates when no key columns are specified.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog

Authenticating Your API Request

To access the PDF4me Web API through Power Automate, every request must include a valid API key. Authentication validates your identity and enables the connector to reach PDF4me's Excel row merging service from your flow.

Important Facts You Should Not Miss

Merge Key Columns decides what gets grouped
Columns listed as keys identify duplicate rows and keep their first-occurrence value. Every other column is treated as a value column and gets merged.
Values merge with a semicolon separator
Non-empty values from matching rows are collected, duplicate values within that set are removed, and what remains is joined with "; ".
Empty Merge Key Columns removes exact duplicates only
With no key columns specified, every column counts as a key, so only rows identical across all columns are collapsed and no value merging occurs.
Power Automate PDF4me Excel Merge Rows action showing File Content, File Name, Worksheet Numbers, Merge Key Columns, and Output Format fields

Map File Content and File Name from a prior action, set Worksheet Numbers and Merge Key Columns, then choose Output Format.

Parameters

Required: File Content, File Name, and Worksheet Numbers must always be provided. Merge Key Columns and Output Format are conditional, each with a defined fallback behavior when left blank.

ParameterRequiredWhat it doesExample
File ContentRequiredBase64 or buffer content of the source Excel file, typically mapped from a prior action like SharePoint Get File Content or OneDrive.[File Content from Get File]
File NameRequiredName of the Excel file including its extension, used for processing and naming the output.test.xlsx
Worksheet NumbersRequiredComma-separated list of 1-based worksheet numbers to process, for example "1,3" targets the first and third worksheets.1
Merge Key ColumnsConditionalComma-separated 1-based column numbers used to group duplicate rows. Leave blank to treat all columns as keys, which removes exact duplicate rows without merging any values.6
Output FormatConditionalOutput file format: XLSX, XLS, XLSB, or CSV, matched case-insensitively. Defaults to XLSX when left blank.XLSX

What Does Merge Rows Return?

FieldTypeWhat it contains
documentBase64The Excel document with duplicate rows merged, in the requested Output Format.
FileNameStringOutput filename, for example "merged_rows.xlsx", with the extension matching Output Format.
SuccessBooleantrue when the merge completed, false if the request failed validation or processing.
Error MessageStringDescription of what went wrong, null when Success is true.
ErrorsArrayDetailed error entries with Code and Message, empty when Success is true.

Common Error Messages

Error MessageCauseSolution
Request is emptyRequest object is null.Provide a valid request object.
Document is emptyDocument object is null.Provide a valid Excel document.
Invalid worksheet selectionWorksheet number is out of range or in an invalid format.Use valid 1-based worksheet numbers within the workbook.
Available worksheets in workbook ({X} total)Informational detail returned alongside a worksheet validation failure.Use worksheet numbers from 1 to the reported total.
Worksheet {number} not foundWorksheet number exceeds the workbook's total worksheet count.Use a valid worksheet number from 1 to the total count.
Error processing file: {message}Generic processing error during the merge operation.Check file integrity, data structure, and parameter values.

How Do I Set Up Merge Rows in Power Automate?

  1. Add PDF4meMerge Rows to your Power Automate flow.
  2. Map File Content and File Name from a previous action, such as SharePoint or OneDrive Get File Content.
  3. Enter Worksheet Numbers as a comma-separated list of 1-based worksheet indexes, for example 1 or 1,3.
  4. Enter Merge Key Columns as 1-based column numbers to group on, for example 6, or leave blank to only remove exact duplicate rows.
  5. Set Output Format to XLSX, XLS, XLSB, or CSV, or leave blank for the XLSX default.
  6. Run the flow. Duplicate rows are grouped and merged, and the consolidated file returns as document.

When Should I Leave Merge Key Columns Blank?

Leave Merge Key Columns blank when the goal is only to remove rows that are completely identical across every column, such as cleaning up an import that picked up the same record twice. Because every column is treated as part of the key in this mode, no non-key columns remain to merge, so the action behaves as a straightforward exact-duplicate remover rather than a value consolidator.

Typical Setups

Workflow ExamplesCommon Power Automate flow patterns using Merge Rows.
Customer order consolidation
  1. A recurrence trigger runs after a daily order export completes.
  2. Get File Content retrieves the day's orders workbook from SharePoint.
  3. Merge Rows runs with Merge Key Columns set to the CustomerID column and Worksheet Numbers set to "1".
  4. The consolidated file, with one row per customer and order details merged, is emailed to the sales team.
Import cleanup with exact-duplicate removal
  1. A flow starts when a new file lands in a "Cleanup" SharePoint folder.
  2. Get File Content retrieves the uploaded Excel file that may contain repeated rows.
  3. Merge Rows runs with Merge Key Columns left blank, so only rows identical across every column are collapsed.
  4. The cleaned file is saved back to a "Cleaned Data" folder.
Category-level inventory rollup
  1. A weekly recurrence trigger kicks off inventory reporting.
  2. Get File Content retrieves the detailed inventory workbook from the system of record.
  3. Merge Rows runs with Merge Key Columns set to the Category and Subcategory column numbers.
  4. Product IDs and quantities from matching rows are merged into a single row per category, then archived to the weekly summaries library.

Practical Tips

Pick key columns deliberately
Any column not listed in Merge Key Columns becomes a value column that gets merged. Double-check the column numbers against the worksheet before running the flow on production data.
Merged values lose their original row context
Once several rows are combined with a semicolon separator, you can no longer tell which merged value came from which original row unless a key column preserves that link.
Column numbers are 1-based, not 0-based
Column 1 is column A, column 2 is column B, and so on. Passing a 0-based index will target the wrong column.
Duplicate values within a merge group are removed once
If three duplicate rows share the same value in a non-key column, that value appears only once in the merged cell rather than being repeated three times.
Worksheet Numbers applies the same merge logic per sheet
When multiple worksheet numbers are listed, each worksheet is merged independently using the same Merge Key Columns setting.

Cheat Sheet

FieldValue
ActionMerge Rows
File ContentMapped from a prior file-retrieval action
File Namee.g. test.xlsx
Worksheet Numbers1-based, comma-separated: "1" or "1,3,5"
Merge Key Columns1-based column numbers to group on, e.g. "6"; blank = exact duplicates only
Value merge separator"; " between deduplicated non-key values
Output FormatXLSX (default), XLS, XLSB, or CSV
Outputdocument (Base64), FileName, Success, Error Message, Errors

Frequently Asked Questions

How do I merge duplicate rows in Excel using Power Automate?+
Add the PDF4me Merge Rows action, map File Content and File Name from a prior action, set Worksheet Numbers, and enter Merge Key Columns as the 1-based column numbers that identify a duplicate row. Non-key values from matching rows are combined into a single row with a semicolon separator.
What happens if Merge Key Columns is left empty?+
Leaving Merge Key Columns empty treats every column as part of the key, so only rows that are 100 percent identical across all columns are merged. This mode removes exact duplicate rows without combining any values, since there are no non-key columns left to merge.
How are values combined when rows are merged?+
For each non-key column, PDF4me collects the non-empty values from every matching row, removes duplicate values within that set, and joins what remains with a semicolon and space separator. See <a href="https://learn.microsoft.com/en-us/office/vba/api/excel.range.consolidate" target="_blank" rel="noopener noreferrer">Microsoft's Excel consolidation reference</a> for how native Excel handles a similar grouping concept.
Can I merge rows across multiple worksheets in one request?+
Yes. Worksheet Numbers accepts a comma-separated list of 1-based worksheet indexes, such as 1,3,5, and the merge runs independently on each specified worksheet within the same file.
Which output formats does Merge Rows support?+
Output Format accepts XLSX, XLS, XLSB, or CSV, matched case-insensitively. XLSX is the default and offers the widest compatibility. See <a href="https://learn.microsoft.com/en-us/connectors/pdf4meconnect/" target="_blank" rel="noopener noreferrer">the PDF4me Power Automate connector reference</a> for the full action list.

Industry Use Cases & Applications

Sales & E-Commerce Use Cases

  • Customer Order Consolidation: Merge multiple orders per customer into single rows
  • Product Sales Aggregation: Consolidate sales by product across multiple transactions
  • Territory Rollup: Merge sales data by territory or region
  • Duplicate Lead Removal: Remove exact duplicate leads from marketing lists

Same Task on Other Platforms

Get Help