How to Use Math Functions

by Chaknith Bin

IronXL is a powerful tool in Excel that facilitates math aggregation functions such as Average, Sum, Min, and Max. These functions are essential for performing calculations and analyzing data. With IronXL, you can harness the capabilities of these math functions to derive insights, make informed decisions, and effectively analyze numerical data in Excel without the use of Interop.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Aggregate Functions Example

When working with ranges of cells in an Excel spreadsheet, you can utilize various aggregate functions to perform calculations. Here are some essential methods:

  • The Sum() method calculates the total sum of the selected range of cells.
  • The Avg() method determines the average value of the selected range of cells.
  • The Min() method identifies the minimum number within the selected range of cells.
  • The Max() method finds the maximum number within the selected range of cells.

These functions are valuable tools for analyzing data and deriving meaningful insights from your Excel spreadsheets.

Please note
Non-numerical values will not be included in the calculation.

:path=/static-assets/excel/content-code-examples/how-to/math-functions-math-functions.cs
using IronXL;
using System.Linq;

WorkBook workBook = WorkBook.Load("sample.xls");
WorkSheet workSheet = workBook.WorkSheets.First();

// Get range from worksheet
var range = workSheet["A1:A8"];

// Calculate the sum of numeric cells within the range
decimal sum = range.Sum();

// Calculate the average value of numeric cells within the range
decimal avg = range.Avg();

// Identify the maximum value among numeric cells within the range
decimal max = range.Max();

// Identify the minimum value among numeric cells within the range
decimal min = range.Min();
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

For more flexibility, the above functions can also be applied to single/multiple row or column. Learn more about selecting row and column.

Chaknith related to Aggregate Functions Example

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.