Icon

Calculate Totals - Multiple Files

<p><strong>Calculate Totals - Multiple Files</strong></p><p>This workflow shows how to calculate the totals of multiple files using KNIME Analytics Platform.</p><p>The aim is to concatenate the input tables (same structure) from five files and calculate the totals of the Olympic medal counts for the countries that participated in the Olympic Summer Games from 1896 to 2020.</p><p>💡 <em>To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.</em></p><p>Let's walk through the different nodes involved in this operation:</p><p><strong>Excel Reader node:</strong></p><ul><li><p>Since the folder with the data is already included when you download the workflow, in the "File and Sheet" tab, we choose to "Read from" the "Current workflow data area" and also check the option "Mode: Files in folder".</p></li><li><p>We know that all the files from the target folder have the same structure (standard format, data in the first sheet). By selecting the above configuration, we can easily read and concatenate all of them using the Excel Reader node.</p></li></ul><p><strong>Column Filter node:</strong></p><ul><li><p>We clean the input tables from unnecessary columns, which we don't need for the total calculation.</p></li></ul><p><strong>Row Aggregator node:</strong></p><ul><li><p>We set the "Category column" to "country" to total the medals by country.</p></li><li><p>We manually select the columns we want to aggregate the rows of, namely "gold", "silver", and "bronze".</p></li><li><p>As the "Aggregation" method, we use the "Sum" option.</p></li><li><p>We also want to calculate the grand totals by enabling the "Additional grand totals at second output port" flag.</p></li></ul><p><strong>Sorter node:</strong></p><ul><li><p>We sort the medal totals for each country by the number of gold medals in descending order.</p></li></ul><p><strong>Constant Value Column + Column Resorter nodes:</strong></p><ul><li><p>We create a row which contains the grand medal totals over all countries.</p></li></ul><p><strong>Concatenate node:</strong></p><ul><li><p>We can control how the two input tables will be concatenated. Since our two input tables have the same structure, we use the intersection mode. There is the option of either using intersection or union columns mode.</p></li><li><p>We choose the "Append suffix" option to handle duplicate row ids with the suffix "_dup". It means that if we have two rows with the id "Row0", one gets changed to "Row0_dup".</p></li></ul><p><strong>Excel Writer:</strong></p><ul><li><p>We create a new file called "Olympic_games_Medal_Countries_Totals_1896-2020" and save it in the workflow data area.</p></li><li><p>After executing the node, the file will open automatically.</p></li></ul><p>As you can see from the output, we calculated each country's medal totals and appended the grand medal totals in the last row.</p>

Calculate Totals - Multiples Files


This workflow demonstrates how to clean, aggregate, and format spreadsheet data for further analysis or reporting, and lastly exports the resulting data table to an external file.

In this example, we access the medal counts of the 1896-2020 Olympic Games from five separate Excel files (identical table structure). We proceed to filter the data to include only specific columns ("country", "gold", "silver", "bronze") and calculate the total medal count for each country as well as the grand totals. We concatenate the aggregated data into one data table and lastly write the table to a new Excel file.

For a detailed overview of each node in this workflow, refer to the workflow description in the Info panel.


💡 To view each node's configuration, select the node and see the configuration pane on the right side of the workflow editor.

Data access

Read all files in folder "Olympic Games Medal Count 1896-2020"

Data manipulation

  • Keep only relevant columns

  • Calculate total medal count for each country and sort in descending order; Calculate grand total over all countries

  • Concatenate country totals and grand total

Data export

Save resulting table as new file

Sort by gold medalsin descending order
Sorter
Column Resorter
Read Olympic gamesfiles from folder
Excel Reader
Clean the table from unnecessary columns
Column Filter
Concatenate total medals for each country with the grand totals
Concatenate
Save resulting table as new file: Olympic_Games_Medal_Countries_Totals_1896-2020.xlsx
Excel Writer
Top: Medal count for each countryBottom: Grand totals over all countries
Row Aggregator
Add "country" column withconstant value "Grand totals"
Constant Value Column Appender

Nodes

Extensions

Links