Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Calculating Statistical Values on Different-Sized Subsets of Data.

Calculating Statistical Values on Different-Sized Subsets of Data

by Allen Wyatt
(last updated April 12, 2014)

2

Chris has a huge amount of data in a worksheet and he wants to analyze the data based on different groupings within it. For instance, he has data in cells A2:B36001, where row 1 contains the column headings Time and Signal. He wants to divide the data into groups consisting of some arbitrary number of sequential values, and then extract, for each group, a mean value for the Time, a mean value for the Signal, and a standard deviation for the Signal.

The easiest way to handle this type of requirement is to add a column that is used to indicate a group number for each row. Follow these steps:

  1. Put the heading Group into cell C1.
  2. In cell E1 enter the number of values that should be in each group. For instance, if you want each group to contain 10 sequential values, enter the number 10 in cell E1.
  3. In cell C2 enter this formula: =INT((ROW()-ROW($C$2))/$E$1)+1
  4. Copy the formula in cell C2 to the range C3:C36001. Column C now contains a "group number" for each row, based on the value in cell E1. If E1 is 10, you end up with 3600 groups, 1 through 3600. If E1 is 100, you end up with 360 groups, 1 through 360.

With the group numbers set up, you are ready to do the analysis. There are a couple of ways you can do this. One way is to use the subtotaling capabilities of Excel. Select one of the cells in the data area and follow these steps:

  1. Choose Subtotals from the Data menu. Excel displays the Subtotal dialog box.
  2. Change the At Every Change In drop-down list to Group.
  3. Change the Use Function drop-down list to indicate the type of statistic you want to calculate for each group.
  4. Change the Add Subtotal To area so that only Time or Signal are selected, as appropriate.
  5. Click OK.

Excel groups and subtotals the data, as directed. (This process may take a while depending on the size of your groups.) You can hide the detail and only show the subtotals by clicking on the small 2 (with the box around it) in the outline area at the left of the worksheet. If you later want to change what is calculated, or if you need to change the number of items in each group, just remove the subtotals (using the button in the Subtotal dialog box) and repeat the above steps.

Another way to derive the statistics from your data is to use a PivotTable. Make sure that there are no subtotals in the data and select a cell within the data. Then follow these steps:

  1. Display the Insert tab of the ribbon.
  2. Click the PivotTable tool. (This tool is the first one at the left of the Insert tab.) Excel displays the Create PivotTable dialog box.
  3. Click OK. (The default options in the dialog box are just fine.) Excel creates a blank PivotTable and displays a field list at the right of the worksheet.
  4. Drag the Group field to the Row Labels area, just below the field list.
  5. Drag the Time field to the Values area, just below the field list.
  6. Drag the Signal field to the Values area, just below the field list.
  7. Drag the Signal field, once again, to the Values area. The PivotTable should now show "Count of Time," "Sum of Signal," and "Sum of Signal2."
  8. In the Values area, click the "Count of Time" label. Excel displays a Context menu.
  9. Choose Value Field Settings. Excel displays the Value Field Settings dialog box.
  10. In the Summarize Value Field By list, choose Average.
  11. Click OK. The "Count of Time" labels change to "Average of Time."
  12. In the Values area, click the "Sum of Signal" label. Excel displays a Context menu.
  13. Choose Value Field Settings. Excel displays the Value Field Settings dialog box.
  14. In the Summarize Value Field By list, choose Average.
  15. Click OK. The "Sum of Signal" labels change to "Average of Signal."
  16. In the Values area, click the "Sum of Signal2" label. Excel displays a Context menu.
  17. Choose Value Field Settings. Excel displays the Value Field Settings dialog box.
  18. In the Summarize Value Field By list, choose StdDev.
  19. Click OK. The "Sum of Signal" labels change to "StdDev of Signal."

You now how the data desired. If you need to change the number of data items in each group, just go back to the data worksheet and change cell E1 to a different value. You can then return to the PivotTable, display the Options tab of the ribbon, and click the Refresh button.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8628) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Calculating Statistical Values on Different-Sized Subsets of Data.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Expanding a Custom Dictionary

Does Word tell you that your custom dictionary is full? It might not actually be full, but even if it is you can add another ...

Discover More

Using Call to Run VBA Macros

An elegant way to run macros from within macros is to use the Call statement. In order to use it, you need to provide a ...

Discover More

Wrapping Text Around a Graphic

Place a graphic in your document, and you may want to make sure that your document text "wraps" around the edges of the ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Entering Formulas in Excel

The primary way you signify that you are entering a formula is to start a cell entry with an equal sign. The equal sign is ...

Discover More

Changing the Reference in a Named Range

Define a named range today and you may want to change the definition at some future point. It's rather easy to do, as ...

Discover More

Pulling Formulas from a Worksheet

The formulas in your worksheet can be displayed (instead of formula results) by a simple configuration change. You can then ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 9?

2014-04-14 02:22:26

barouh

Thank you for this useful tip. And any ideas on what is the best way to solve the similar task, when we want to calculate not the means, but the medians for X subcategories?


2014-04-12 11:49:36

Willy Vanhaelen

ROW($C$2) will always return 2 so instead of =INT((ROW()-ROW($C$2))/$E$1)+1 you can better use =INT((ROW()-2)/$E$1)+1


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.