How to use Excel’s SUMIF function to calculate totals by category

four trays of varieties of fruits

If you have a large data set in Excel and you want to calculate totals based on specific criteria, such as sales by region or expenses by department, you can use the SUMIF function. Here’s how:

  1. Open your Excel workbook and select the cell where you want to display the total.
  2. Type =SUMIF( followed by the range of cells that contain the categories you want to sum (e.g., A1:A10), a comma (,), and the criteria you want to use to filter/indicate the category in that range (e.g., "North").
  3. Type another comma (,) followed by the range of cells that contain the values you want to sum (e.g., B1:B10).
  4. Close the parentheses and press Enter.

Your total will be displayed in the selected cell.

Here’s an example formula:

=SUMIF(A2:A5,"North",B2:B5)

This formula will sum all values in column B (e.g., “Sales”) where the corresponding value in column A is “North.”

Example Data Set

Here’s some sample data I’ll use to demonstrate the SUMIF function’s potential.

ABC
1RegionSalesExpenses
2North10020
3South20030
4East15025
5West17535
Example data set of sales and expenses by region

Example Scenarios

Here are some examples of how you can use SUM and the SUMIF function with the previous data set example:

ScenarioFormulaResult
Total sales for all regions=SUM(B2:B5)625
Total expenses for all regions=SUM(C2:C5)110
Total sales for the North region=SUMIF(A2:A5,"North",B2:B5)100
Total expenses for the South region=SUMIF(A2:A5,"South",C2:C5)30
Total sales greater than $150=SUMIF(B2:B5,">150")375
Total expenses less than $30=SUMIF(C2:C5,"<30")45
Examples of formulas and results for various needs based on the example data

So now imagine that you have three months’ worth of data and “North” appears three times. Your SUMIF function becomes even more valuable as it only sums the North rows’ values.

Hopefully this helps! Let me know if you have any specific questions about using this function with your data.

References

How to get a distinct count of unique values in Excel

Note: Video demonstration at bottom of post.

In some applications, like Power BI, you can get a distinct count of unique values in a column in just a click or two. But of all the functions in Excel, there isn’t a straightforward “Distinct Count” unfortunately.

There are, however, the following two functions that, when used together, give the desired result:

  • COUNTA – Counts the number of cells in a range that are not empty
  • UNIQUE – Returns the unique values from a range or array

So, we’re listing all the unique values we have in a range or column by using UNIQUE and then nesting it within the COUNTA function to count the number of values returned. Here are three examples:

Distinct count goalFormula example
Distinct count for a range of cells=COUNTA(UNIQUE(E19:E26))
Distinct count for a table column when referenced within the same table=COUNTA(UNIQUE([Project]))
Distinct count for a table column when referenced outside the table=COUNTA(UNIQUE(Table1[Project]))

Be sure to replace the cell range, column name, and/or table and column name in the formulas with your own.

A video demonstration of this formula in use is embedded below.

How to get total week days or business days between dates in Excel

When working with dates in Excel, you can get the number of days between two dates using the DAYS() or NETWORKDAYS() formulas.

  • DAYS() will return the total number of days, including weekends.
  • NETWORKDAYS() removes weekends and only gives you the count of only the business/week days between two dates.

You could use DAYS() to quickly get total time passed between two dates such as:

  • How many days or years (divide by 365) an employee has been on staff
  • How much time passed between ticket creation and resolution
  • How much time was spent traveling

Whereas NETWORKDAYS() can be used to get metrics such as:

  • How many business days were spent on a project
  • How many week days are available for allotment to a future project
  • How many school days are in the year

The structure of the formulas and their arguments are as follows:

DAYS() = end date, start date (i.e. =DAYS(End, Start) -or- =DAYS(D2,C2))

NETWORKDAYS() = start date, end date, holidays to exclude (i.e. =NETWORKDAYS(Start, End, Sheet2!B2:B8) -or- =NETWORKDAYS(C2,D2,Table1[Date]))

NETWORKDAYS() formula in Excel contains arguments for start date, end date, and holidays to exclude.

I’ve created an example workbook that demonstrates both of these formulas in action. You can download the example here.

Note: For NETWORKDAYS, I placed the holidays table on a separate sheet named Holidays. This allows me to add and remove rows easily for more or fewer holidays without needing to adjust my formulas. You could, alternatively, just use a range of dates (i.e. Holidays!B2:B8) whether or not it’s part of a table but that could result in incorrect information if you don’t also update your formulas to include additional holiday rows when added.

Get business days between dates in Excel with modified weekend parameters

If your weekends aren’t Saturday/Sunday, or you just want to exclude certain days of the week from your calculations, you can alternatively use NETWORKDAYS.INTL instead of NETWORKDAYS. This adds an additional argument after end date and before holidays that allows you specify which day(s) to exclude as the weekends.

NETWORKDAYS.INTL() is structured as follows: start date, end date, weekends, holidays. The following screenshot shows the options available for the weekend argument:

NETWORKDAYS.INTL() includes an argument for weekend specification.

Delete random blank Excel cells and shift remaining cells left to fill the gaps

Photo by Andrea Albanese from Pexels

I love learning new things. Today I was using a CSV export of data in Excel and was just using Excel to reassemble the data. At one point it resembled something like:

This is, of course, after some manipulation. Basically I removed the parts of a URL column expanded by delimiter (“/”) I didn’t want. This left awkward gaps and all I wanted was to quickly delete the gaps and shift contents of remaining cells to the left to sort of “reconstruct” each row without gaps. Since they didn’t line up in neat columns, I needed a different method.

I found a great article that helped. To summarize the steps:

  1. Select the range for which you’ll delete blank cells and shift data left.
  2. Press Ctrl+G.
  3. Click Special… (lower left of dialog)
  4. Choose the Blanks radio button
  5. Click OK.
  6. All blank cells in the selected range remain highlighted. Now right-click any of the selected blank cells.
  7. Choose Delete.
  8. Select Shift cells left.
  9. Click OK.

Here’s an animated GIF showing the process on my example data:

Click to enlarge

Workaround: Export to Excel not working in Safari, Chrome, or other non-IE browsers for SharePoint server list exports

The problem

If you’re using SharePoint Online (M365) you won’t run into this issue. But for those of you, like me, who are still on SharePoint 2013 or 2016 you may have tried to use “Export to Excel” on a SharePoint list or library and received the following error message:

To export a list, you must have a Microsoft SharePoint Foundation-compatible application.

Clicking “OK” only redirects you to page that is most definitely not an Excel export:

The workaround

Using Internet Explorer to open and export your SharePoint list might be the simplest way to export your list. However, some are unable to use IE.

If you can’t download or use Internet Explorer (IE) you can still get your lists exported to Excel by working in reverse. Rather than export from SharePoint we are going to open Excel and import from SharePoint.

1. Open a blank workbook in Excel

2. Navigate to the Data ribbon –> Get Data > From Other Sources > From SharePoint List

Note: There are two SharePoint list options under Get Data. Do not select From Online Services > From SharePoint Online list (this option would be for O365 only and O365 users will not need this post’s workaround).

3. Paste the URL to your SharePoint site. You can paste the URL to the list you’re wanting to import, but delete everything after the site’s name in the URL.

4. Click OK.

5. Select Windows and leave credentials as the default “Use my current credentials” unless you have reason to access the list as another account (perhaps a service account which may be able to retrieve all items even with restricted item-level permissions).

6. Click Connect.

7. Find the name of the list you want to import, select it, and click Load.

Click to enlarge

8. Depending on the size of your list, this may take a while. Once imported, you’ll find all of your data as well as some SharePoint metadata associated with your list items.

Click to enlarge

While not ideal, it doesn’t take long to do and you do get the result you’re looking for (with a bit of cleanup, deleting unnecessary columns and such).

Some things to keep in mind:

  • Exporting from SharePoint using IE allows you to export a view.
  • Importing from SharePoint using Excel imports every single list item and column, regardless of view.
  • You’re only able to import items to which you at least have view permissions.

Capitalize whole words or first letters of each word in Excel cells

Since Excel doesn’t have the same set of robust text transformation tools as Word, we need creative ways to get the same effects sometimes. When it comes to auto-capitalizing whole words or first letters of words, there are two functions you can use:

  • =UPPER() will capitalize the entire cell contents
  • =PROPER() will capitalize first letters of each word in a cell

In the GIFs below, you’ll notice I demonstrate both. The steps for both are exactly the same, so just pick the formula/function you need.

Since nobody wants to add another column to a sheet unnecessarily, we’ll just temporarily create a column for the calculation, copy the result, then delete it. You may, alternatively, wish to just hide it for later use or keep it alongside the original for a purpose.

Insert column and formula

  1. Insert column
  2. Place formula of choice in top cell of column and drag down (lower right-hand box/handle of cell) or press enter if in table format as seen below
Click to enlarge

Copy new values over originals and delete temporary column

Next we’ll use the “Paste values” feature to remove the formula dependency of the resulting data and keep just the newly formatted text.

“Paste Values” icon when pasting in Excel. This option copies just the values resulting from a formula so you don’t “break” your data/calculations when moving/deleting.
  1. Copy values
  2. Paste (special) values only over original column values to replace them with the correct capitalization version
  3. Delete temporary column
Click to enlarge

Filter even or odd rows in Excel

This morning I pasted a list of values into Excel in which the pattern consisted of a “good value” followed by that same value with a minor adjustment. The second, near-duplicate value wasn’t useful to me so I wanted to filter out all even rows so I’d just have the first of each near-duplicate.

I say near-duplicate because if your values truly are duplicates, you can just use the Remove Duplicates function.

So to filter odds and evens, we’ll add a new column to the right of our data and set the formula to:

=ISEVEN(ROW())

This evaluates the data’s row number as even or odd and will return TRUE if the number is even or FALSE if not. Double-click the handle in the lower right of the cell to fill down.

Then we filter the column for just TRUE (evens) or FALSE (odds). You can right-click the value you want to keep > Filter > Filter by Selected Cell’s Value

Click to enlarge

Remove duplicate values from an Excel column

A simple trick in Excel allows you to remove duplicate values from a column in Excel. Depending on your version of Excel, yours may look a bit differently but the process is nearly the same. Below, I’m using Excel 2016.

1. Select the column, or the values from which you’re removing duplicates.
Note: You could also just start with step 2, and then select the relevant column(s) from the resulting dialog.
2. Go to Data > Remove duplicates (in the Data Tools panel)

3. Confirm if your column has a header (column title or not) and click OK.

4. Excel will confirm the number of duplicates found and how many remain. Click OK.

Solution: “Feature requires a browser that supports ActiveX controls” when importing spreadsheet to SharePoint

If you’re trying to import a spreadsheet as a new list in SharePoint, you’ll need to use a browser that supports ActiveX controls or you’ll get the error:

“This feature requires a browser that supports ActiveX controls.”

Chances are you’re running a browser other than IE, or you’re running IE version 11. ActiveX controls are not supported in IE11, or most browsers. We can work around this error message by having IE pretend it’s version 10 momentarily.

  1. Open SharePoint in Internet Explorer (IE)
    • Quick access: Hit Windows key, type IE, hit enter
  2. Press F12 to open Developer Tools and select the Emulation Tab
  3. Change Document mode from 11 to 10 (supports ActiveX). Page will reload so you can try again in version 10.

Now try to import the spreadsheet again and it will work fine, opening your spreadsheet and prompting you to select the table or relevant data for import.

Preserve Excel hyperlinks when saving as PDF

If you have hyperlinks in your excel files and need to save your file as a PDF, you’ve probably run into the error in which your hyperlinks in the PDF output are inactive.

To be able to maintain hyperlinks you will need Adobe Acrobat. If you don’t have it, please skip down to the bottom of this post to the “Don’t have Adobe Acrobat?” section.

If you do have Adobe, it’s quite simple unless you’re using the HYPERLINK() formula (see below). Just use the Acrobat add-in to save as Adobe PDF.

File –> Save as Adobe PDF –> Convert to PDF. You can also use the Acrobat tab in the ribbon and click “Create PDF”.

Using HYPERLINK() formula

If you’re using the hyperlink formula, as seen below, we’ll need to do some manipulation to our sheet first. Printing to PDF will require that your hyperlinks are properly written before conversion (http… or https…).


To get just the hyperlinks from our formula, we can copy values from Excel and paste into Word, then copy from Word and paste back into Excel (keeping source formatting).

Paste into blank Word document, then copy all values (not the whole table, just the column)
Back in Excel, select the original column values, and paste the new values copied from Word in their place

Now when you save as Adobe PDF, your links will remain active:

Don’t have Adobe Acrobat?

Save the Excel Sheet as a web page and links will work. This isn’t ideal but in a pinch will save you some stress.