IRONSOFTWAREHOME
Master Excel Aggregate Functions in C#
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"];

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

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

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

// Identify minimum value of all numeric cells within the range
decimal min = range.Min();
Imports IronXL
Imports System.Linq

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

' Get range from worksheet
Dim range = workSheet("A1:A8")

' Apply sum of all numeric cells within the range
Dim sum As Decimal = range.Sum()

' Apply average value of all numeric cells within the range
Dim avg As Decimal = range.Avg()

' Identify maximum value of all numeric cells within the range
Dim max As Decimal = range.Max()

' Identify minimum value of all numeric cells within the range
Dim min As Decimal = range.Min()
NuGet Download
PM > Install-Package IronXL.Excel
Master Excel Aggregate Functions in C#

Master Excel Aggregate Functions in C#

The code example above shows how to easily get aggregate values from a range of cells in an Excel spreadsheet. However, please note that any non-numerical cell will be left out.

Sum

The method Sum() returns the total sum of the selected range of cells.

Average

The method Avg() returns the average of the selected range of cells.

Minimum

The method Min() returns the minimum number among the selected range of cells.

Maximum

The method Max() returns the maximum number among the selected range of cells.

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

Explore Math Functions in Excel Using C#
View on GitHub

Ready to Get Started?

Nuget Downloads 2,237,574Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required