GM Excel Formula Library

44 formulas for sales, operations and HR reporting. Each has the syntax, a worked example on the same sample data, the result and the mistake to avoid.

Sample data

All examples read from this sheet, named "Data", so you can check any result by hand.

Sample sales data
ABCDEFGHJ
1RegionRepMonthProductUnitsUnit priceSalesTargetOrder date
2NorthAliJanTea12045054,00050,0002026-01-05
3NorthSaraJanJuice8030024,00030,0002026-01-12
4SouthOmarJanTea15045067,50060,0002026-01-18
5EastHinaJanBiscuits20012024,00020,0002026-01-25
6NorthAliFebJuice9530028,50030,0002026-02-03
7NorthSaraFebTea11045049,50045,0002026-02-10
8SouthOmarFebBiscuits30012036,00040,0002026-02-16
9EastHinaFebTea9045040,50045,0002026-02-24
10NorthAliMarBiscuits25012030,00025,0002026-03-04
11NorthSaraMarJuice13030039,00035,0002026-03-11
12SouthOmarMarJuice7030021,00030,0002026-03-19
13EastHinaMarTea16045072,00060,0002026-03-27

Column I in the workbook is hidden. Names and figures are made up for practice.

Sheet "Lookup"
ABCE
1ProductCategoryList priceMessy name
2TeaBeverage450 ali raza
3JuiceBeverage300
4BiscuitsSnack120

Find a formula

44 formulas

Totals and counting

SUM

Syntax: SUM(number1, [number2], …)

Adds numbers or whole ranges.

=SUM(Data!G2:G13)

Result with the sample data: 486,000

Watch out: Numbers stored as text are skipped without any warning. Compare COUNT with COUNTA to find them.

All versions

SUMIF

Syntax: SUMIF(range, criteria, [sum_range])

Adds the values that meet one condition.

=SUMIF(Data!A2:A13,"North",Data!G2:G13)

Result with the sample data: 225,000

Watch out: The sum range comes last here, but first in SUMIFS.

All versions

SUMIFS

Syntax: SUMIFS(sum_range, criteria_range1, criteria1, …)

Adds the values that meet several conditions at once.

=SUMIFS(Data!G2:G13,Data!A2:A13,"North",Data!C2:C13,"Jan")

Result with the sample data: 78,000

Watch out: Every range must be the same size, or the formula returns #VALUE!.

Excel 2007 and later

COUNT

Syntax: COUNT(value1, [value2], …)

Counts the cells that contain numbers.

=COUNT(Data!E2:E13)

Result with the sample data: 12

Watch out: Text that looks like a number is not counted.

All versions

COUNTA

Syntax: COUNTA(value1, [value2], …)

Counts the cells that are not empty.

=COUNTA(Data!B2:B13)

Result with the sample data: 12

Watch out: A cell holding an empty text result ("") still counts as filled.

All versions

COUNTIF

Syntax: COUNTIF(range, criteria)

Counts the cells that meet one condition.

=COUNTIF(Data!D2:D13,"Tea")

Result with the sample data: 5

Watch out: Put comparisons in quotes, for example ">100".

All versions

COUNTIFS

Syntax: COUNTIFS(criteria_range1, criteria1, …)

Counts the rows that meet several conditions.

=COUNTIFS(Data!A2:A13,"North",Data!G2:G13,">30000")

Result with the sample data: 3

Watch out: To compare with a cell, join the sign and the cell: ">"&H1.

Excel 2007 and later

AVERAGE

Syntax: AVERAGE(number1, [number2], …)

Returns the arithmetic mean.

=AVERAGE(Data!G2:G13)

Result with the sample data: 40,500.00

Watch out: Empty cells are ignored but zeros are included, which changes the result.

All versions

AVERAGEIFS

Syntax: AVERAGEIFS(average_range, criteria_range1, criteria1, …)

Averages only the rows that meet your conditions.

=AVERAGEIFS(Data!G2:G13,Data!D2:D13,"Tea")

Result with the sample data: 56,700.00

Watch out: If nothing matches, the result is #DIV/0!.

Excel 2007 and later

MAX

Syntax: MAX(number1, [number2], …)

Returns the largest value.

=MAX(Data!G2:G13)

Result with the sample data: 72,000

Watch out: Text and empty cells are ignored.

All versions

MIN

Syntax: MIN(number1, [number2], …)

Returns the smallest value.

=MIN(Data!G2:G13)

Result with the sample data: 21,000

Watch out: A zero used as a placeholder will become the minimum.

All versions

MAXIFS

Syntax: MAXIFS(max_range, criteria_range1, criteria1, …)

Returns the largest value among rows that meet your conditions.

=MAXIFS(Data!G2:G13,Data!A2:A13,"South")

Result with the sample data: 67,500

Watch out: It returns 0, not an error, when nothing matches.

Excel 2019 or Microsoft 365

SUBTOTAL

Syntax: SUBTOTAL(function_num, ref1, …)

Totals a list and ignores rows hidden by a filter. Function 9 means sum.

=SUBTOTAL(9,Data!G2:G13)

Result with the sample data: 486,000

Watch out: Use 109 instead of 9 to also ignore rows you hid by hand.

All versions

SUMPRODUCT

Syntax: SUMPRODUCT(array1, [array2], …)

Multiplies matching items and adds the results.

=SUMPRODUCT(Data!E2:E13,Data!F2:F13)

Result with the sample data: 486,000

Watch out: The arrays must have the same number of rows and columns.

All versions

Lookup

VLOOKUP

Syntax: VLOOKUP(lookup_value, table_array, col_index_num, FALSE)

Finds a value in the first column of a table and returns a value from the same row.

=VLOOKUP("Juice",Lookup!A2:C4,3,FALSE)

Result with the sample data: 300

Watch out: Leaving out FALSE gives an approximate match, which can return a wrong value without warning.

All versions

INDEX and MATCH

Syntax: INDEX(return_range, MATCH(lookup_value, lookup_range, 0))

Looks up in any direction and works in every version.

=INDEX(Lookup!A2:A4,MATCH(120,Lookup!C2:C4,0))

Result with the sample data: Biscuits

Watch out: Keep both ranges the same height and use 0 for an exact match.

All versions

XLOOKUP

Syntax: XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found])

A modern lookup that can search left or right and shows your own message when nothing is found.

=XLOOKUP("Coffee",Lookup!A2:A4,Lookup!C2:C4,"Not found")

Result with the sample data: Not found

Watch out: It is not available in Excel 2019 or earlier. Use INDEX and MATCH for older versions.

Excel 2021 or Microsoft 365

Logic and errors

IF

Syntax: IF(logical_test, value_if_true, value_if_false)

Chooses between two results.

=IF(Data!G2>=Data!H2,"Met","Missed")

Result with the sample data: Met

Watch out: Put text results in quotes.

All versions

IFS

Syntax: IFS(test1, value1, test2, value2, …)

Checks conditions in order and returns the first that is true.

=IFS(Data!G3>=Data!H3,"Met",Data!G3>=Data!H3*0.8,"Close",TRUE,"Missed")

Result with the sample data: Close

Watch out: End with TRUE as the catch-all, or unmatched rows show #N/A.

Excel 2019 or Microsoft 365

AND

Syntax: AND(logical1, [logical2], …)

True only when every condition is true.

=IF(AND(Data!E2>100,Data!G2>50000),"Yes","No")

Result with the sample data: Yes

Watch out: AND gives one answer for a whole range; it does not test row by row.

All versions

OR

Syntax: OR(logical1, [logical2], …)

True when at least one condition is true.

=IF(OR(Data!A2="East",Data!D2="Tea"),"Yes","No")

Result with the sample data: Yes

Watch out: Repeat the cell for each test: OR(A2="North",A2="East"), not OR(A2="North","East").

All versions

IFERROR

Syntax: IFERROR(value, value_if_error)

Shows your own result instead of an error.

=IFERROR(Data!G2/0,0)

Result with the sample data: 0

Watch out: It hides every error, including broken references. For lookups, show a visible message instead of 0.

All versions

Text

TRIM

Syntax: TRIM(text)

Removes extra spaces, leaving single spaces between words.

=TRIM(Lookup!E2)

Result with the sample data: ali raza

Watch out: It does not remove non-breaking spaces copied from web pages.

All versions

PROPER

Syntax: PROPER(text)

Capitalises the first letter of each word.

=PROPER(TRIM(Lookup!E2))

Result with the sample data: Ali Raza

Watch out: Names such as McDonald need a manual check.

All versions

UPPER

Syntax: UPPER(text)

Changes text to capital letters.

=UPPER(Data!A2)

Result with the sample data: NORTH

Watch out: Lookups already ignore capitals, so this is for display.

All versions

LEFT

Syntax: LEFT(text, [num_chars])

Takes characters from the start of a text.

=LEFT(Data!D5,3)

Result with the sample data: Bis

Watch out: The result is text, even when it looks like a number.

All versions

MID

Syntax: MID(text, start_num, num_chars)

Takes characters from the middle of a text.

=MID("GM-2026-014",4,4)

Result with the sample data: 2026

Watch out: Positions start at 1, and spaces count.

All versions

LEN

Syntax: LEN(text)

Counts the characters in a cell.

=LEN(TRIM(Lookup!E2))

Result with the sample data: 8

Watch out: Compare with LEN of the untrimmed cell to find hidden spaces.

All versions

SUBSTITUTE

Syntax: SUBSTITUTE(text, old_text, new_text, [instance_num])

Replaces one piece of text with another.

=SUBSTITUTE("0300-123-4567","-","")

Result with the sample data: 03001234567

Watch out: It is case-sensitive.

All versions

TEXTJOIN

Syntax: TEXTJOIN(delimiter, ignore_empty, text1, …)

Joins many cells with a separator.

=TEXTJOIN(", ",TRUE,Lookup!A2:A4)

Result with the sample data: Tea, Juice, Biscuits

Watch out: Set the second argument to TRUE to skip empty cells.

Excel 2019 or Microsoft 365

TEXT

Syntax: TEXT(value, format_text)

Turns a number or date into text in a chosen format.

=TEXT(Data!G2,"#,##0")

Result with the sample data: 54,000

Watch out: The result is text and cannot be summed. Format codes can differ with regional settings.

All versions

Dates

EOMONTH

Syntax: EOMONTH(start_date, months)

Returns the last day of a month, before or after a date.

=EOMONTH(Data!J2,0)

Result with the sample data: 2026-01-31

Watch out: Format the result cell as a date, or you will see a serial number.

All versions

NETWORKDAYS

Syntax: NETWORKDAYS(start_date, end_date, [holidays])

Counts Monday to Friday between two dates, including both ends.

=NETWORKDAYS(DATE(2026,3,1),DATE(2026,3,31))

Result with the sample data: 22

Watch out: For Friday and Saturday or Sunday-only weekends, use NETWORKDAYS.INTL.

All versions

DATEDIF

Syntax: DATEDIF(start_date, end_date, unit)

Counts complete years or months between two dates.

=DATEDIF(DATE(2022,6,15),DATE(2026,11,25),"Y")

Result with the sample data: 4

Watch out: Excel does not suggest it as you type. Microsoft advises against the "MD" unit.

All versions

WEEKDAY

Syntax: WEEKDAY(date, [return_type])

Returns the day of the week as a number. With type 2, Monday is 1.

=WEEKDAY(Data!J2,2)

Result with the sample data: 1

Watch out: Without the second argument, Sunday is 1.

All versions

Analysis for sales and operations

Target achievement %

Syntax: actual / target

Shows how much of a target has been reached.

=SUM(Data!G2:G13)/SUM(Data!H2:H13)

Result with the sample data: 103.4%

Watch out: For a team, divide total actual by total target. Do not average each person's percentage.

All versions

Growth %

Syntax: (new - old) / old

Measures change from one period to the next.

=(SUMIFS(Data!G2:G13,Data!C2:C13,"Mar")-SUMIFS(Data!G2:G13,Data!C2:C13,"Feb"))/SUMIFS(Data!G2:G13,Data!C2:C13,"Feb")

Result with the sample data: 4.9%

Watch out: If the old value is zero or negative, the percentage has no useful meaning.

All versions

Weighted average

Syntax: SUMPRODUCT(values, weights) / SUM(weights)

Averages values where some count more than others. Here, the average selling price per unit.

=SUMPRODUCT(Data!F2:F13,Data!E2:E13)/SUM(Data!E2:E13)

Result with the sample data: 276.92

Watch out: A simple average of prices ignores how many units were sold at each price.

All versions

Running total

Syntax: SUM($G$2:G2) copied down

Adds up values as you go down a list. The example is the total after six rows.

=SUM(Data!$G$2:G7)

Result with the sample data: 247,500

Watch out: Lock only the starting cell with $ so the end moves as you copy.

All versions

RANK

Syntax: RANK(number, ref, [order])

Shows the position of a number in a list.

=RANK(Data!G2,Data!$G$2:$G$13,0)

Result with the sample data: 3

Watch out: Lock the list with $. Equal values get the same rank.

All versions

LARGE

Syntax: LARGE(array, k)

Returns the k-th largest value.

=LARGE(Data!G2:G13,3)

Result with the sample data: 54,000

Watch out: k cannot be larger than the number of values.

All versions

ROUND

Syntax: ROUND(number, num_digits)

Rounds to a chosen number of decimal places. Negative places round to tens, hundreds or thousands.

=ROUND(AVERAGE(Data!G2:G13),-2)

Result with the sample data: 40,500

Watch out: Formatting hides decimals but keeps them. ROUND changes the stored value.

All versions

FILTER

Syntax: FILTER(array, include, [if_empty])

Returns the rows that meet a condition. Here the results are added up.

=SUM(FILTER(Data!G2:G13,Data!A2:A13="East"))

Result with the sample data: 136,500

Watch out: It needs empty cells below and beside it, or it shows #SPILL!.

Excel 2021 or Microsoft 365

UNIQUE

Syntax: UNIQUE(array)

Lists each value once. Here the unique regions are counted.

=COUNTA(UNIQUE(Data!A2:A13))

Result with the sample data: 3

Watch out: Extra spaces make two entries look different. Clean the data first.

Excel 2021 or Microsoft 365

Where to go next

Read Excel formulas for sales operations, try the business calculator lab, or see the ready-made Excel templates.

Questions

Do these formulas work in Google Sheets?

Many of them use the same names there, but they have only been checked in Microsoft Excel. Test any formula in Google Sheets before relying on it.

Why do I see #NAME? in my Excel?

Your version does not have that function, or the name is misspelled. Each card shows which versions include it. XLOOKUP, FILTER and UNIQUE need Excel 2021 or Microsoft 365.

Why does my formula need semicolons instead of commas?

Some regional settings use a semicolon to separate arguments. Replace the commas with semicolons if Excel rejects a formula.

How were the results checked?

The example workbook was opened and recalculated in Microsoft Excel, and each result was compared with an answer worked out separately. That check covers the sample data only.

Can I use the example workbook for work?

Yes, you can use and change it for your own work. The data in it is made up. Check your own results before sharing reports.

Function names are Microsoft's. For full reference pages, see Microsoft Support. This library is general information; check results before using them for decisions.

Spending hours on the same Excel steps?

We can automate the repeat work in your workbook, with a written scope and price before anything starts.