# Consolidation of several Excel files and the addition of the source column

**URL:** <https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582>\
**Category:** KNIME Extensions\
**Tags:** text-processing\
**Created:** [January 16, 2024, 1:08am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582 "2024-01-16T01:08:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex1368](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@alex1368](https://forum.knime.com/u/alex1368)\
**Post date:** [January 16, 2024, 1:08am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/1 "2024-01-16T01:08:59Z")

</div>

Hello  
I have a folder containing several excel files that I want to merge together.  
I want the name of each Excel file to be inserted as source in a separate column in the consolidated file and displayed in the output.  
Please guide me in this regard  
Sample file that I have  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/f/9f5018af541f00a7cdc9ccb7944873e5cc1d0964.png)  
Sample file in my mind  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/a/0a9c35c919978413554f956f4ef1d5b6865808d5.png)

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [January 16, 2024, 1:56am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/2 "2024-01-16T01:56:26Z")

</div>

See if this helps.

> [@Merge multiple CSVs into one and add the file name as column](https://forum.knime.com/t/merge-multiple-csvs-into-one-and-add-the-file-name-as-column/37643):
>
> I can merge CSVs now but my question is how do i add the source file name as a column on the consolidated file?

---

<div class="post-metadata">

**Author:** ![alex1368](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@alex1368](https://forum.knime.com/u/alex1368)\
**Post date:** [January 16, 2024, 2:02am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/3 "2024-01-16T02:02:58Z")

</div>

This is exactly my question

---

<div class="post-metadata">

**Author:** ![rfeigel](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@rfeigel](https://forum.knime.com/u/rfeigel)\
**Post date:** [January 16, 2024, 2:05am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/4 "2024-01-16T02:05:21Z")

</div>

Look at the response which shows how to configure the reader.

---

<div class="post-metadata">

**Author:** ![tqAkshay95](https://forum-cdn.knime.com/user_avatar/forum.knime.com/tqakshay95/32/67469_2.png) [@tqAkshay95](https://forum.knime.com/u/tqAkshay95)\
**Post date:** [January 16, 2024, 7:41am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/5 "2024-01-16T07:41:14Z")

</div>

Hello @alex1368 ,

You design a workflow like the following attached image and configure each node

also, I attached a workflow sample for you and try it.

input data:

![Screenshot 2024-01-16 130547](https://forum-cdn.knime.com/uploads/default/original/3X/0/0/00ccecd87d4fb67568dd652945e9d27b36f45a55.png)

![Screenshot 2024-01-16 141823](https://forum-cdn.knime.com/uploads/default/original/3X/1/9/19b8d78c7c061ee3985c33ae97f2b2e034e9ca0f.png)

![Screenshot 2024-01-16 130507](https://forum-cdn.knime.com/uploads/default/original/3X/0/0/006e556dbfe312be8012b1feeef2e467861793e4.png)

Workflow:

 ![Screenshot 2024-01-16 141319](https://forum-cdn.knime.com/uploads/default/original/3X/5/f/5f4e4a8e033585609bd9dcc6b9f63813debb688e.png)

output:

 ![new](https://forum-cdn.knime.com/uploads/default/original/3X/7/d/7d27f712cd8fe5f39291da665e70b6f8980ef528.png)

workflow:

[merge\_multiple\_file.knwf](https://forum.knime.com/uploads/short-url/lBhMPwFdgvfUtwlXDQLKETcXudO.knwf) (17.5 KB)

---

<div class="post-metadata">

**Author:** ![takbb](https://forum-cdn.knime.com/user_avatar/forum.knime.com/takbb/32/57077_2.png) [@takbb](https://forum.knime.com/u/takbb)\
**Post date:** [January 16, 2024, 10:49am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/6 "2024-01-16T10:49:00Z")

</div>

Hi @tqAkshay95 and @alex1368, the workflow you proposed would work, but just to clarify… similar to the post referenced by @rfeigel, which related to CSV files but which applies equally to the Excel Reader, there is no need to perform the loop as the Reader can do the whole job by itself, if there isn’t additional functionality required.

You may also be interested to know an alternative loop if you _were_ going to use a loop (perhaps because there was some other functionality needed on a “per file” basis), or maybe you want to [introduce error handling around the Excel Reader](https://forum.knime.com/t/excel-reader/72040/5) so you can handle problems with specific files (which is certainly a very good reason for using a loop instead), the Table Row to Variable loop would perform the operation of the Chunk Loop + Table Row to Variable combination, and a Variable To Table Column could take the place of the Cross Joiner if it were needed

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/6/36e92fa912aa41801970ba48e02209603f6a1c80.png)

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/7/47fdae8e9197d1e939672e02a6b32e8e5de9f464.png)

But… for this specific case, the Excel Reader alone should do the job (and this is what @rfeigel was referring to)

![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/1/e12ba002478a8e597d64d89ba6ab0c63a813c2d0.png)

The “folder” option on the “File and Sheet” tab replaces the need for the loop as it can read all files in a folder, and the filter options can restrict the list if necessary:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/2/624aa0ead42ecf48b6aaf07da667e7dedda20bf9.png)

On the “Advanced” tab (KNIME 5.2), you’ll find the ability to “Append file path column” as shown below.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/0/f/0fbf357956dd1f11e79b82ea3a755e77d95b5bf8.png)

_In KNIME 4.7, this is the “Advanced Settings” tab, and this tab looks quite different, but the option appears as “Append path column” just above the preview pane._

Turning on “Support changing schemas” means that if on an execution of the workflow, you’ve changed the layout of the Excel files, it will work with the new layout (schema). If you are reading multiple files, then “Fail if schemas differ” may be a useful option, if you are expecting all files to match the same format, but if your workflow can correctly handle the situation if they don’t (e.g. some files have missing/additional columns), then untick that option.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [April 15, 2024, 10:49am UTC](https://forum.knime.com/t/consolidation-of-several-excel-files-and-the-addition-of-the-source-column/76582/7 "2024-04-15T10:49:03Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
