It is a useful substitute and a real timesaver compared to complex nested IF formulas. It is more compact and easier to read.

The SWITCH function compares an expression (cell value) against a list of values, and performs the result for the matching value. If a match is not found, a default result can be set.

=SWITCH(expression, value1, result1, [default_or_value2, result2])

*Expression* is the value to be tested against the list of values. This is typically a reference to a cell value such as A2.

*Value1, value2, …* is the value to be compared against the expression.

*Result1, Result2, …* is the action to perform if *Value* is a match to the expression.

*Default* is the action performed if no values match the expression.

Here we can see the strengths and weaknesses of the SWITCH function.

It only refers to the expression once, which is great. While nested IFs will constantly reference the expression in each logical test it performs.

However as a negative, you cannot use logical operators such as >, < or = in the expression. It simply matches the values in its list to an expression, and cannot test if a value is larger or smaller.

In this example, the values in column B are compared against the sequence of values in the SWITCH function – Red, Green and Yellow. Then the resulting discount is returned.

If no matching value is found, then *Not a valid membership* is returned.

=SWITCH(B2,"Red",10%,"Green",14%,"Yellow",18%,"Not a valid membership")

A nested IF formula would have looked like below.

=IF(B2="Red",10%,IF(B2="Green",14%,IF(B2="Yellow",18%,"Not a valid membership")))

Cell B2 is constantly referenced in each IF test. There is no disguising the simplicity of SWITCH in comparison.

This is just 3 tests. If there were many more the difference would have been glaring.

Let’s have a look at the SWITCH function with the ever popular VLOOKUP.

In this example, the SWITCH function returns a different lookup table for each value in the list.

=VLOOKUP(C2,SWITCH(B2,"red",$F$2:$G$6,"Green",$F$9:$G$13,"Yellow",$I$2:$J$6,"Not a valid membership"),2,TRUE)

So here we have created a conditional lookup formula that returns a discount dependent upon the membership they have, and the price ordered.

These two examples demonstrate how useful an addition SWITCH is to the family of logical functions. And although you can’t beat the classic IF function, SWITCH can certainly simplify the more complex ones.

Many of you reading this may already be familiar with the FIND function. You would probably have used it with LEFT or MID to locate a delimiter character, and return text before, or after that character.

In this tutorial we want to extract text after the last occurrence of a character, so want to create a reverse find effect.

In this example we were working with the data below in column A. We wanted to extract the text after the final hyphen character.

Each cell contains a varying number of hyphens, so we need to identify the position of the last occurrence of the character, and then extract the text.

The completed Excel formula for this reverse string search is shown below.

=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"-","*",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))))

This formula is a monster so a detailed explanation is shown below. The video above also explains it step by step.

The first job on our hands is to return the total occurrences of the hyphen character.

Our ultimate aim is to retrieve some text after the last occurrence, so we need to know how many there are in total.

The formula below uses the SUBSTITUTE function to replace all occurrences of a hyphen with nothing. A LEN function is used to count the number of characters remaining when the hyphens are removed.

This value is subtracted from the total number of characters in the cell, leaving us with the answer to the total number of hyphens.

LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))

We will now replace the last occurrence of the hyphen with a unique character, which we can then use to easily extract the text we want.

An asterisk (*) has been used in this example as the unique marker. It could have been any text character.

The brilliant SUBSTITUTE function is used to accomplish this, with a little help from some friends.

The previous part of the formula has been used in the instance number argument of the SUBSTITUTE function, to specify to replace the last hyphen.

SUBSTITUTE(A2,"-","*",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))

Now that we have inserted a unique marker in the position of the final delimiter character, it is time to find it and extract the text we want.

The following formula was added to what we have from the previous step. The ??? represents the formula part from the previous step.

=RIGHT(A2,LEN(A2)-FIND("*",???))

The RIGHT function is used to extract text from the end of cell A2.

To calculate the number of characters to extract, the LEN function returns the total characters in the cell. And then the FIND function locates our unique marker character.

The position of the marker character is subtracted from the total characters in the cell.

The final formula is as below.

=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"-","*",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))))

This can be adjusted to return text from the second from last delimiter, or anything you want really.

You now have a way of searching a string from right-to-left, in addition to the typical left-to-right search.

This blog post explores 4 alternatives which are easier, faster and cleaner than the classic nested IF.

Lets start with a function that is new from Excel 2016 called the IFS function.

This function was introduced to condense and simplify the task of writing nested IFs. You can avoid all of those brackets that come with opening and closing multiple IF functions.

In the example below we used an IFS function to calculate the price for each membership type. There are four types of membership (platinum, gold, silver and bronze).

The IFS function tests cell B2 for each membership type and applies the correct price.

=IFS(B2="Platinum",110,B2="Gold",90,B2="Silver",65,B2="Bronze",40)

I believe an even better alternative to the IFS function for this scenario would be a lookup.

Now you can use any lookup formula that you like to achieve this. In this example I will use VLOOKUP.

By creating a lookup table (F4:G7 below) we are able to use the following VLOOKUP function to search for each membership and return the correct price.

=VLOOKUP(B2,$F$4:$G$7,2,FALSE)

This is very compact and easier to adapt in the future. If a membership price changes, you can just change the lookup table. There is no need for someone to have to edit the formula, which you or your colleagues may not be comfortable doing 10 months from now.

In this alternative formula we use VLOOKUP again, but this time for a range lookup.

Take the example below where we have a list of exam scores and we need to assign a grade for each score.

A nested IF approach could look like this.

=IF(A2>=90%,"A",IF(A2>=80%,"B",IF(A2>=70%,"C",IF(A2>=60%,"D",IF(A2>=50%,"E","F")))))

Or even like this.

=IF(AND(A2>=90%,A2<=100%),"A",IF(AND(A2>=80%,A2<90%),"B",IF(AND(A2>=70%,A2<80%),"C",IF(AND(A2>=60%,A2<70%),"D",IF(AND(A2>=50%,A2<60%),"E","F")))))

Now these formulas work perfectly. However they are complex and messy. And unless your trying to impress someone with big complex looking functions, there are better ways.

With the lookup table set up in range E4:F9 we could use this VLOOKUP function.

=VLOOKUP(A2,$E$4:$F$9,2,TRUE)

Much simpler.

This is a range lookup, so it is essential that the first column of the lookup table (column E) is in ascending order.

This last alternative to the nested IF formula is a bit of a secret function. Many Excel users will never have even heard of the CHOOSE function.

This function will perform an action based on a specific index number. And that makes it perfect for use with form controls.

So in this example I have an interactive chart being driven from a combo box control.

The image below may look a little messy. Typically some of this data would be hidden or stored on separate sheets. It is all on one sheet here to get a better idea of how it works.

The first 7 rows have data of the top goal scorers from 4 different football leagues in the 2016-17 season. A combo box is on the left and is linked to cell A9. A selection from the 4 leagues in the combo box will produce index number 1, 2, 3 or 4 in cell A9.

Formulas are in cells D9 and range D11:E15 returning the correct data for the chart from the combo box selection. This is easier explained in the video.

Now in the cells mentioned above we could use a nested IF like below. This is the nested IF from cell D11 which returns the name of that leagues top goal scorer.

=IF(A9=1,A3,IF(A9=2,D3,IF(A9=3,G3,IF(A9=4,J3))))

Or we could use this awesome and simple little CHOOSE function. It checks the index value in cell A9 and then returns the relevant information from its list.

=CHOOSE($A$9,A3,D3,G3,J3)

I hope you found these nested IF alternatives useful. Check out these other Excel formula tutorials.

]]>In this blog post we look at why you might want to use the CHAR function, and some examples of it in action in Excel.

The CHAR function is typically used to insert, or to find, a character which you ordinarily cannot type from your keyboard.

To use it you will need to find out what the code is for the character you want to use.

You can search online for a full list of these character sets so that you know each code (or at least the one you need at the given time). These character sets differ between the Windows and Mac computers, and are also dependent upon the language used.

The most common use of the CHAR function is surely to insert line breaks when concatenating text with a formula.

When typing in Excel you can use the Alt + Enter keys together to insert a line break manually. But if you are dealing with hundreds or thousands of downloaded data, that you want to present differently, then the CHAR function is here to help.

In the example below the formula was used in cell E2 to join the text from each cell together with a line break between each cell content. The text from the cells in column E also needing wrapping.

=A2&CHAR(10)&B2&CHAR(10)&C2&CHAR(10)&D2

The line break is character 10 from my keyboards character set. I looked that up before writing the formula.

Another useful CHAR function example would be to remove unwanted characters from cells.

When downloading data, or copying from the web, you can receive what may look like strange characters. You need these removed before you can start analysing your data.

In column A of the image below the text is on separate lines and a strange symbol has appeared before each word.

The SUBSTITUTE function can be used, with the CHAR function, to remove these characters (this tutorial shows four more ways to clean text in a cell).

The formula below used two SUBSTITUTE functions. The first one removes the strange question mark symbol, the second one then removes the line break and replaces it with a comma and space.

=SUBSTITUTE(SUBSTITUTE(A1,CHAR(12),""),CHAR(10),", ")

There are 5 reasons for your Excel formula not calculating are many. In this tutorial we explain these scenarios.

The first thing that you should check is that the calculation options are not set to manual. This is the most likely problem.

Click the **Formulas** tab and then the **Calculation Options** button.

If this is set to manual, the formulas will not update unless you press the **Calculate Now** or **Calculate Sheet** buttons.

Change it to **Automatic** and the formulas will start working.

This setting can be changed by macros, or by other workbooks that you may have opened first. So if you are not aware of this setting, it could still be a reason for the formula not calculating.

Another common reasons is accidentally formatting the cells containing formulas as text. These will not calculate whilst in this format.

To check this; click on the cell and check the Number group of the **Home** tab.

If it displays **Text**. Change the format to **General** using the list provided.

Then re-calculate the formula in the cell by double clicking on the cell and pressing Enter.

When typing the formula be sure not to enter a space before the equals. This is difficult to notice so can go unrecognised, however it will prevent the formula from calculating.

Double click the cell, or edit it in the Formula Bar. Check if there is a space and if so delete it. The formula will update.

When an apostrophe (‘) is entered before typing in Excel, that tells Excel to store the content as text. This is a common approach to store numbers such as phone numbers as text to retain the leading zeros.

This however could be the reason why your formula is not calculating.

The apostrophe will not be visible in the cell on the spreadsheet, but you can see it in the Formula Bar.

Double click the cell, or edit it in the Formula Bar and delete the apostrophe.

The final reason could be that the **Show Formulas** button on the **Formulas** tab is turned on. This can easily be done accidentally, or possibly by someone else using this workbook previously.

This button is used when auditing formulas. It shows the formula instead of the formula result, stopping them from calculating. This can be helpful when troubleshooting formula problems.

Simply click the **Show Formulas** button again to turn it off and the formula will be working.

Fortunately Excel provides a variety of methods to group time depending on what you need. In this blog post we look at 4 ways to group times using PivotTables and Excel formulas.

PivotTables make it very easy to group numeric data such as dates and times including grouping time by the hour.

If you have a list of times, simply drag the time column into the Rows area of the PivotTable.

In Excel 2016, the PivotTable automatically groups it by the hour, minute and second. Previous versions do not, but have the same options.

Group a time field by right mouse clicking on a cell containing a time and select **Group**. Then choose the group options you want.

PivotTables are great, but they cannot help if you want to group time into specific intervals such as every 30 minutes, or every 4 hours.

In this video the FLOOR function is used to group time into 6 hour intervals, each quarter of the day.

We then create a PivotTable and use these intervals as a label in the report.

The FLOOR function will always round down to a multiple that you specify. If you need to round to the nearest multiple, it is not good enough.

Say for example that you want to round to the nearest 15 minutes. So a time of 00:18:30 should be rounded down to 00:15:00, but a time of 00:22:40 should round up to 00:30:00.

For this we can use the MROUND function of Excel. This function will round a value to the nearest multiple that you specify, which in this example is 15 minutes.

In the final example we look at using the VLOOKUP function to group time into irregular intervals.

In this video to day is split into morning, day, evening and night. However these parts of the day are not specific intervals such as every 6 hours. The morning is 5 hours between 06:00 and 11:00, then the daytime is 6 hours between 11:00 and 17:00 etc.

These intervals are set by creating a lookup table. A VLOOKUP is then set up to do an approximate match (range lookup) for each time within this table.

- Count how many times a specific character appears
- Formula to match records on different worksheets
- 5 awesome date functions
- Convert text into a date format

]]>

In this blog post we explore 4 Excel MOD function examples. Hopefully this will help to see how versatile this function can be.

To start we better have a quick introduction to how to use the MOD function. It looks like this;

=MOD(number, divisor)

You need to provide it first with the number you want to divide, and then the number you want to divide it by (divisor).

You can see some basic examples of this below.

Ok, lets get on with some more impressive **real-world MOD function examples**.

Here is the video tutorial of the examples explained below.

Excel stores dates and times as a number. The time is the fractional part of that number.

For example, the date and time 06/07/2017 10:15 is stored in Excel as 42922.42708.

Now this does not mean anything to us, but to extract the time part only of .42708 we could use the MOD function and then format the result as time to make sense to us.

The MOD function would be used to divide the number (date and time value) by 1. As this would leave the fractional part as the remainder.

In the example below the following formula was used to extract the time result.

=MOD(A2,1)

This calculation was used in my tutorial to calculate the time elapsed in days, hours and minutes.

Another clever example of the MOD function may be to stop the entry of odd numbers in a range.

If a number is an even number, a remainder of 0 would be returned when divided by 2.

It stands to reason then that odd numbers would return a different remainder. We could use this understanding to insert the MOD function into a Data Validation rule.

Select the range of cells you want to apply the validation rule to. Click **Data** > **Data Validation**.

Select **Custom** from the Allow list and enter the formula below into the box provided.

=MOD(A2,2)=0

In this formula, cell A2 is the first cell of the range that you selected. This formula ensures that only values that return a remainder of 0 when divided by 2 are allowed.

In my online course on how to create automated sports league tables and tournaments in Excel, I have a section on calculating cricket statistics and league tables.

This example comes from that course. We have cells containing the number of overs bowled, but we want to see how many balls is this.

For those who don’t follow cricket. There are 6 balls per over bowled. So if a bowler has made 6.2 overs. They have done 6 overs of 6 balls each and then 2 more balls.

In the spreadsheet below the number of overs is in column B and then the following formula was used in C.

=INT(B3)*6+MOD(B3,1)*10

This formula used the INT function to extract the integer part of column B and multiplies it by 6 to calculate the total balls bowled.

Then the MOD function is used to extract the fractional part (.2 in B3) by dividing it by 1. This is then multiplied by 10 to convert 0.2 to 2. The two parts of the formula are then added together.

For the final example, we will use the MOD function to help us sum every third cell in a range. This formula can be adapted to sum every other cell, or every fifth cell, or whatever you may need.

This formula uses the impressive SUMPRODUCT function, a favourite of mine.

The formula below uses the ROW function to return the row number of the cell reference starting with B3. A 2 is then subtracted from this because the range starts from row 3. So row 3 is actually row 1 of the range.

The MOD function is then used to divide this number by 3. If the number is divisible by 3 then it must be a multiple of 3.

The number that meet this test in range B3:B11 are then summed.

=SUMPRODUCT((MOD(ROW($B$3:$B$11)-2,3)=0)*($B$3:$B$11))

The purpose of VLOOKUP is to look for a value and return some information about that value. Although quite specific in its role, this function can be used in some very clever and interesting ways.

For anyone reading this who may be quite new to VLOOKUP, lets have a quick look at its structure.

=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

**Lookup Value** – The value you want to look for.

**Table Array** – The table containing the value to look for and value to return.

**Col Index Num** – The column number of the Table Array containing the value to return.

**Range Lookup** – Optional argument. To specify whether an approximate or exact match on the Lookup Value is needed.

For more information on how to use VLOOKUP, check out the Ultimate VLOOKUP guide.

If you would prefer to watch the video, or simply watch it whilst you refer to the formulas in this tutorial. You can do so below.

This is one of the more common reasons to use the VLOOKUP function. You can create a lookup table and automate data entry by getting VLOOKUP to fetch it for you.

In this simple example we have a travel expense spreadsheet. Someone regularly travels to five different offices. They enter where they went, and need VLOOKUP to return the miles for that office from a table.

The VLOOKUP formula below has been used in cell B3.

=VLOOKUP(A3,$F$2:$G$6,2,FALSE)

VLOOKUP can be a great alternative to complex nested IFS and formulas that contain IF and AND to handle their complex logic.

Take this example where the size of the discount increases the higher the quantity you order.

The quantity required and discount qualified for can be seen in columns F and G. Without VLOOKUP this could be a sizeable formula.

The following VLOOKUP formula is used in cell C2. It uses an approximate lookup, otherwise known as a range lookup, to return the correct discount depending on where the value sits in the ranges of column F.

The TRUE on the end of VLOOKUP is specifying to perform a range lookup.

=VLOOKUP(A2,$F$2:$G$7,2,TRUE)

A very impressive way to use VLOOKUP is on your reports and dashboards to make your charts and visualisations dynamic.

Lets say you had three tables of sales data like below. As you can see, these are sales of product categories in Canada, Denmark and France.

You have one chart and you would like the user to select which countries data to view from a drop down list.

Well in the image below the drop down list is in cell D2. When the user selects a country from the list, the VLOOKUP’s in column B return the correct data.

Here is the VLOOKUP formula from cell B3;

=VLOOKUP(A3,INDIRECT($D$2),2,FALSE)

The three tables of data have each been named using the countries name. The INDIRECT function has then been used in VLOOKUP to refer to that table from the users list selection.

A very common task for Excel users is to compare lists, and VLOOKUP can help here too.

In this basic example below we have two lists of fruit. A VLOOKUP function has been used in a Conditional Formatting rule to identify the fruit that appears in the first list, but not the second.

The formula below was used in the Conditional Formatting rule.

=ISNA(VLOOKUP($A2,$C$2:$C$8,1,FALSE))

It uses VLOOKUP to look for the item of fruit from the first list in the second. The ISNA function then reports TRUE if the fruit is not found.

To apply the Conditional Formatting rule;

- Select the range of cells to format. In this example it was A2:A7.
- Click
**Home**>**Conditional Formatting**>**New Rule**. - Select
**Use a formula to determine which cells to format**and then enter the formula in the box provided, and click the Format button to select your formatting options.

This blog post explores some examples of using **wildcard characters in formulas** to find, sum or count cells containing partial matches to what we are searching for.

If you prefer a video tutorial then check it out below, otherwise please continue for the written tutorial.

Before we look at some examples of wildcards in formulas, we should discuss the three types of wildcard characters you can use in Excel.

*** (asterisk)**– represents any number of characters. For example,*In**could mean India, Indonesia, Indianapolis, Innsbruck.**? (question mark)**– represents one single character. For example,*L?ndon*could mean London, or Landon.**~ (tilde)**– used to identify a wildcard character in the text. For example, if you wanted to find the exact phrase**London*in the text, you would enter*~*London*. Otherwise all entries ending with the word London would be returned because of the asterisk wildcard.

I assume we are all big fans of VLOOKUP. The most well known lookup function of Excel. But did you know that by using wildcard characters you can create a partial text match with VLOOKUP?

The following formula has been used in cell E3. The ampersand (&) has been used to concatenate the location in cell D3 with the asterisk wildcard. So this VLOOKUP will find the first value that begins with the text in D3.

Sometimes you do not know, or in this case do not need to know the full name of what you are looking for, and a partial match in itself is unique.

=VLOOKUP(D3&"*",$A$2:$B$10,2,FALSE)

Learn more in our Ultimate Guide to VLOOKUP.

The COUNTIF and SUMIF functions of Excel are also two of its most commonly used functions. It makes sense therefore that wildcards can be used with them.

In the example below we have a list of invoices and amounts. The first two characters of each invoice determine the sales rep involved.

We do not care about the exact invoice number right now. Just as long as the first two characters match the sales rep I am reporting on, then fantastic.

This COUNTIF function was used in cell E3 to calculate the number of orders by the sales rep SJ. In similar fashion to the preceding VLOOKUP example, cell D3 and the asterisk character are joined to create the criteria.

=COUNTIF(A2:A11,D3&"*")

This SUMIF function was then used in cell F3 to total the orders for SJ, or whatever sales rep is entered into D3.

=SUMIF(A2:A11,D3&"*",B2:B11)

In this example, we imagine a list of invoice numbers which should all be 6 characters in length. We want to test the range of invoice numbers to check if there are any inconsistencies.

The formula below uses a COUNTIF function and the question mark wildcard. By entering 6 question marks in a string we are counting the cells containing exactly 6 characters.

The answer in cell C2 is 7 indicating that there must be 3 that do not meet that criteria. Can you see them? Well in the next example we will get Conditional Formatting to highlight them.

=COUNTIF(A2:A11,"??????")

This formula can be added into a Conditional Formatting rule to identify the cells containing the incorrect text length.

The formula below has been used. It is slightly different to the COUNTIF in the previous example.

=COUNTIF(A2,"<>??????")

Because it is part of a Conditional Formatting rule, it only references the single cell (A2). This is the first cell of the range. The formatting is applied to the entire range of cells, but in the formula you reference just a single cell.

If you are not familiar with the “<>” symbol, that is the NOT operator. It has been included in the string with the six question marks. So this rule will format all the cells that do not have 6 characters.

Wildcard characters can be used in more functions that what I have demonstrated here. Using them with IF, FIND and SUBSTITUTE can be useful also.

If you can perform formulas on the full content of a cell that fantastic, but when you do not know the full content, wildcards do a great job of stepping up to the plate.

- Excel formula to display the sheet name in a cell
- Find the least frequent value in a list
- Prevent formulas from showing in the formula bar
- Pick a name at random from a list

]]>

The SUMPRODUCT function is powerful, versatile and expansive. It is the go to function when looking for an alternative to array formulas.

If you are a newbie – check out our SUMPRODUCT function guide to get an understanding of how it works.

**Ok, are you ready to rock on with these 5 awesome SUMPRODUCT examples?**

Let’s do this.

If you prefer to watch videos, check out this video covering the tutorials from this blog post.

In the first example, we will use the SUMPRODUCT function to return the count and sum of the values from a specific month.

In this example the formula below has been entered into cell E3 to count the values for the month specified in cell D3.

=SUMPRODUCT(--(MONTH($A$2:$A$12)=$D$3))

The MONTH function has been used to extract the month from the each date in the range. This is then tested to see if it is equal to the month we want to count.

The double hyphens ‘–‘ are used to convert the true and false responses of this logical test to 1 and 0. The SUMPRODUCT then sums these 1’s and 0’s to return the answer.

The formula below has then be entered into cell F3 to return the total sales value for that month.

=SUMPRODUCT(--(MONTH($A$2:$A$12)=$D$3),B2:B12)

For this we just needed to add a comma and then the range of cells containing the sales values.

This works because the SUMPRODUCT function multiplies the 1’s and 0’s from month test by these sales values. And then these results are all summed.

This example can be very useful if you have to analyse comments, feedback or SEO keyword data. In these situations you will have large volumes of text and you may be looking for the occurrence of specific words.

In this example, the SUMPRODUCT formula has been used in cell D2 to count all the occurrences of words entered in cell C2.

=SUMPRODUCT(--(ISNUMBER(FIND(C2,A2:A9))))

In this formula the FIND function searches for the words in each cell. If the words are found then FIND returns its starting position, and if not it returns and error value.

The ISNUMBER function will then return true if a number is returned, or false if not. The double hyphens are then used just like the previous example to convert the true and false to 1 and 0.

The 1’s and 0’s are then summed by SUMPRODUCT to return the final count.

The SUMPRODUCT function can also be used to perform a unique count of values in a range.

Being able to count how many orders and how many training sessions is great. But sometimes you need to know how many different customers placed orders, and how many different training sessions. Then you need a unique count.

The formula below performs a unique count on range A2:A10.

=SUMPRODUCT(1/COUNTIF(A2:A10,A2:A10))

For this to work the COUNTIF function counts the occurrences for each name in the list producing the below. This says that Robert occurs twice, James once and Sally three times etc.

=SUMPRODUCT(1/{2;1;3;2;1;1;3;1;3})

These values are then divided by the 1 producing the below.

=SUMPRODUCT({0.5;1;0.33;0.5;1;1;0.33;1;0.33})

And then SUMPRODUCT sums them all up delivering the unique count.

How about summing only the top values from a range. Yes SUMPRODUCT can do this.

In this example we sum only the top 3 values, but this can easily be adapted to top 5, top 10 or whatever you wish.

The formula below sums only the top 3 values in range B2:B12.

=SUMPRODUCT(LARGE(B2:B12,{1,2,3}))

This formula uses the LARGE function with SUMPRODUCT. The LARGE function is used to return kth largest value in a data set, such as the 5th largest.

In this example we have provided the LARGE function with an array of {1, 2, 3} so that it returns the top 3. The SUMPRODUCT then sums them.

This is all in the beauty of the SUMPRODUCT formula handling arrays of data.

If you need to sum the values from the bottom of the range you can use the SMALL function.

In the final example we see the SUMPRODUCT formula performing a two way lookup.

You may have created two way lookups before in the past. The most common way to do this is to use the INDEX and MATCH function combination.

The formula below performs a two way lookup. It looks for the value of cell B1 down column A, and the value in cell D1 along row 3. It returns the value at the intersection, which in the image is £246.

=SUMPRODUCT((A4:A13=B1)*(A3:M3=D1),A4:M13)

The asterisk (*) is used as an AND operator in this formula. And the second array is the range to return the value from i.e. A4:M13.

The SUMPRODUCT function is so incredibly versatile we could be listing far more examples in this tutorial. For example it can also sum the values from every nth row of a list.

What have you used it for?

- Use the MID and FIND functions to extract text
- 5 awesome uses of the INDIRECT function
- 4 amazing uses of CONCATENATE
- How to use the TEXT function of Excel

]]>