Batch Summary of Multiple Excel Spreadsheet Data – Done in 1 Minute
Tags: excel, spreadsheet, programming, opensource
Published: 2024-02-20 08:01:18

In the workplace, it is often necessary to summarize and sum data from multiple tables. Do you know how to do this?

Today, we will teach you an efficient data aggregation method for several common situations, which can be completed in one minute.

**Type 1: Data comes from multiple Excel files and is summarized into a new Excel file.**

**Type 2: Data comes from multiple sheets in the same Excel, insert a summary sheet.**

Firstly, we need to use a tool called **esProc SPL**, which is a software specifically designed to handle structured table data. It has powerful computing capabilities and is easy to use. After downloading, double-click to install. The examples in this article provide source code that can be copied, pasted, and used.

Download address: [esProc Desktop Download](http://www.scudata.com/download-Desktop/)

## Type 1: Data comes from multiple Excel files and is summarized into a new Excel file

**1）Group and summarize on a single condition**

There are multiple Excel files, each containing daily sales details of several fruit products. Now, we need to summarize the data for several months to calculate the total sales of each fruit.

Before summary:

![Fruit products sheet A before summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu6sev1qf87dyh6xgiaj.png)


![Fruit products sheet B before summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j8xkvpjx0y5jiso0nwi7.png)


After summary:

![Summarized sheet A and sheet B](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uas6typxvhitqxjrcbfc.png)


Firstly, place all the Excel files that need to be summarized in the same folder, for example, in the folder named test on drive D. Then run the code:

```
      A
1    =directory@p(“D:/test/*.xlsx”)
2    =A1.conj(T(~))
3    =A2.groups(Product;sum(DailySales):TotalSales)
4    =file(“D:/test/Total.xlsx”).xlsexport@t(A3)
```

Summary is done!!!

Let’s explain the code:

A1 directory is a function here, meaning to list all .xlsx file names and directories in the test folder.

![The result of A1 function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pyd2unmkqz0s81fp80ua.png)

A2 Open the files in the A1 path in a loop and merge them.

The T() function represents opening a specified path file.

A.()is a loop function, where A1.(T(~)) represents looping through each file path in A1 and opening the file using the T() function. The ~ symbol represents the object for each loop.

After opening all the files in a loop, we also need to merge them, so we add a conj() function, meaning conjunction.

Therefore, the code A1.conj(T(~)) in A2 represents opening the files in A1 and merging them into one table.

A3 Group by product, and get the sum of each product sales as TotalSales.

![The result of A3 grouping and summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iikmgaig42dezx20ezyp.png)

A4 Save summary data as a Total.xlsx file.

**2）Group and summarize on multiple conditions:**

The sales details files mentioned above still needs to summarize the sales amount of each product on a monthly basis and save it in a new Excel file.

Effect after summary:

![Effect after summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vab904nw1510uhxwugfx.png)

Implementation code:

```
      A
1    =directory@p(“D:/test/*.xlsx”)
2    =A1.conj((fn=filename@n(~),T(~).derive(fn:Month)))
3    =A2.groups(Month,Product;sum(DailySales):MonthSales)
4    =file(“D:/test/MonthTotal.xlsx”).xlsexport@t(A3)
```

Summary is done!!!

Code interpretation:

A2 opens each Excel file in a loop, adds the variable Month, with the value of the month from which the data comes, and then merges multiple files.

![the result of A2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ehxmllgjmf15b2l8xqs2.png)

A3 groups and summarizes by Month and Product to get the monthly sales amount of each fruit product.

![the result of A3 grouping and summary](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zgjj2fz4q6dpuzhvfe2.png)

## Type 2: Data comes from multiple sheets in the same Excel file, insert a summary sheet

There are multiple sheets in the same Excel file for the sales details of each product, and a summary sheet needs to be generated to obtain the total sales of each product.

Before summary:

![DailySales of each product](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5weex0mvhals9n3wg2z.png)

After summary:

![TotalSales of each product](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov7gchokb00ie5wkvb5p.png)

Implementation code:

```
      A
1    12
2    =A1.conj(T(“D:/DailySales_2023.xlsx”;~))
3    =A2.groups(Product;sum(DailySales):TotalSales)
4    =file(“D:/DailySales_2023.xlsx”).xlsexport@kt(A3;“Total”)
```

Summary is done!!!

Code interpretation:

A1 Enter the number of sheets to be summarized, such as 12(sheet 1 to 12), which are the sales data for the past 12 months

A2 opens sheets 1 to 12 in a loop and merges them into one table

A3 groups and summarizes by Product to obtain the total sales amount of each product

With the help of SPL tool, data summary from multiple tables can be implemented instantly.

And the syntax of SPL functions is simple, in line with natural logical thinking, and it is not difficult to understand.

Of course, the functions of SPL are not limited to this, and it is not a problem to SPL for Excel operations in various complex scenarios.

For those in need, you can refer to [Desktop and Excel Data Processing Cases](http://c.scudata.com/article/1651916536524). Ninety per cent of Excel problems in the workplace can find answers in this book. The code in the book can basically be copied and used with slight modifications.

If you ever encounter an Excel problem, please always feel free to search answers at esProc Desktop: http://www.scudata.com/esproc-desktop/. It’s absolutely FREE & EASY to download and apply.