Summarizing Data, and Auto Filter (an Overview)

Location: http://www.mvps.org/dmcritchie/excel/sumdata.htm      
Home page: http://www.mvps.org/dmcritchie/excel/excel.htm
[View without Frames]

Auto Filter

 
Conditional Format:   =MOD(SUBTOTAL(3,$C1:D$2),3)=0
Shows color banding working with/without Filtering.

The main purpose of this example is to show filtering by selecting only entries with "Black" as the color.

 A B C
1Prod.  Color  Price 
2AB0010Black 13.50
3AB0011White 13.75
4AB0012 Yellow 14.00
5AB0013Green 14.25
6AB0021Black 14.50
7AB0022 White 14.75
8AB0023Yellow 15.00
9AB0024Green 15.25
10AB0035 Black 15.50
11AB0036White 15.75
12AC0010Black 16.00
13AC0011 White 16.25
   
 A B C
1 Prod. Color  Price 
2AB0010 Black 13.50
6AB0021 Black 14.50
10 AB0035Black 15.50
12AC0010 Black 16.00
16AC0021 Black 14.00
20 AC0035Black 15.00
24AD0010 Black 15.50
28AD0021 Black 13.75
32 AD0035Black 14.75

The above table is a representation of the results of Data, Filter, Auto Filter

By clicking on the list button on Color the following drop down list appears.

All
(Top 10)
(custom)
Black
Green
White
Yellow

Suppose you wanted to show only the items where column C had number of parts to be ordered and you only wanted to show rows with values greater than zero to place an order.

Note the select columns as well as the drop down arrow in C1 have turned blue.  You can use the list as if the other value weren't there -- you can print, copy and paste.

To view all entries under a blued arrow once more, click on the blue arrow and choose "All".

To retain filters but show ALL data, use:  Data --> Filter --> Showall

To undo Auto Filter, simply use Data --> Filter --> (uncheck auto filter)

Auto Filter, Custom

AutoFilter allows you to filter rows in or out depending on values in a column.

With filtering, as with Conditional Formatting, it comes down to a formula or a condition that returns either TRUE or FALSE.

Auto Filter, Limitations

Article ID: Q105322 http://support.microsoft.com/support/kb/articles/q105/3/22.asp < The article is short, so here is a copy... > The information in this article applies to: Microsoft Excel for Windows, versions 5.0, 5.0c Microsoft Excel for the Macintosh, versions 5.0, 5.0a Microsoft Excel for Windows 95, version 7.0 SUMMARY When you use the AutoFilter command to filter data, the resulting drop-down list of unique items is limited to 251 identifiers. If the number of unique identifiers in a list is extremely large, you may receive "Not Enough Memory" errors or your computer may stop responding (hang). NOTE: The limit for Microsoft Excel version 7.0 is 250 due to the addition of one more built-in list item ("Top 10"). The limit in Excel 97 and Excel 98 has been increased to 1000. ----------

You can customize the AutoFilter.  There is a feature described by former Lotus 1-2-3 users that if they place "||" in first cell of a row, it will not be printed.  Excel is more flexible. 

Place "|" or any other character(s) into Column J in each row to be suppressed.  Select Cell J1, which should contain a description of the column then starting from the Data menu item select Filter.  Click on the blue arrow in cell J1.  You could choose blanks, but choose "custom" instead on the left side drop-down, choose "is not equal to".  On the right side drop-down choose "|".

Note the rows that are showing as a result of selection are in Blue.  If you select all cells (Ctrl+A) you will only select the visible cells and can paste those cells elsewhere.

Auto Filter choices:  equals, does not equal, is greater than, is greater than or equal to, is less than, is less than or equal to, begins with, does not begin with, ends with, does not end with, contains, does not contain.

Auto Filter, Custom, Unique

 ABCD
1 Name SeqCnt   =GetFormula(Cn)
2 bob  =COUNTIF(A$2:A2,A2)
3 sara  =COUNTIF(A$2:A3,A3)
4 bob  =COUNTIF(A$2:A4,A4)
5 sara  =COUNTIF(A$2:A5,A5)
6 dave  =COUNTIF(A$2:A6,A6)
7 john  =COUNTIF(A$2:A7,A7)
8 John  =COUNTIF(A$2:A8,A8)
9 Alex  =COUNTIF(A$2:A9,A9)
10 Alex  =COUNTIF(A$2:A10,A10)
11 george 10   =COUNTIF(A$2:A11,A11) 
   
  A
1 Name
2  bob
3  sara
6  dave
7  john
9  Alex
11  george 
  Data --> Filter --> Advanced Filter

Filter this list in place
List Range:  $A:$A
Criteria Range:  (leave blank)
&chk; Unique records only

Only based on Column A, all of
the data on the corresponding rows
would be selected

Hotel Rooms available on a Date, Example

This example would be filtered on Column E, selecting TRUE, to show number of rooms available on the date shown in E1, you could use =Today() for the current date  The Buy and Sell dates, show purchase and sale of the entire hotel. 

 ABCDEFG
1HotelRoomsBuy Sell01/15/198531062 
2Hotel 0132 01/01/1973  TRUE=AND(C2<=$E$1,OR(D2="",D2>=$E$1))  
3Hotel 0220 01/14/197501/15/2000 TRUE=AND(C3<=$E$1,OR(D3="",D3>=$E$1))  
4Hotel 0315 01/26/197701/14/1983 FALSE=AND(C4<=$E$1,OR(D4="",D4>=$E$1))  
5Hotel 04100 02/08/197901/14/1999 TRUE=AND(C5<=$E$1,OR(D5="",D5>=$E$1))  
6Hotel 0530 02/20/1981  TRUE=AND(C6<=$E$1,OR(D6="",D6>=$E$1))  
7Hotel 0620 03/05/198301/31/2000 TRUE=AND(C7<=$E$1,OR(D7="",D7>=$E$1))  
8Hotel 0737 03/17/1985  FALSE=AND(C8<=$E$1,OR(D8="",D8>=$E$1))  
9Hotel 0857 03/30/198712/31/1999 FALSE=AND(C9<=$E$1,OR(D9="",D9>=$E$1))  
10Room Tot.311   TRUE=1=1  
11   Formula used in cell B10: =SUBTOTAL(9,B2:OFFSET(B10,-1,0))  

Pivot Table

Sum of Price 
Color     listTotal
Black132.50
Green  86.00
White134.75
Yellow  87.25
Grand Total440.50
  A Pivot Table is a useful tool for summarizing data.  A pivot table is created from Table -> Pivot Tables, and then using some drag and drop techniques.

Color associated with the product line example is selectable within the Pivot Table shown at left.  If additional fields were included, selecting black only might be more useful.

More information on Pivot tables by Harald Staff in his Introduction To Pivot Tables  If you have Excel 2000 you can copy and paste the sample data into your spreadsheet, and follow right along with the example.  A Pivot table does not update itself, so Harald has also included a macro that makes the tables update on selecting the worksheet:  (Harald wrote XL2GIF macro)   See Related Areas at bottom of this page for additional references.

 

Subtotals

 A B C
1PartQTY Color
2Part_#1 3Black
3Part_#1 1Yellow
4Part_#1 5Red
5Part_#2 4Black
6Part_#3  8Black
7Part_#3 2Red

Picture at the right was created by pasting into in MS PhotoDraw, cropped and saved (size 4K), grey, 85% compression, 324x156 bits, shown at 50%

  Select Column A and Column B
Data --> subtotals -->
    Part / sum / (x) qty
    (x) Replace current subtotals
    (x) Summarize below total
then on spreadsheet view choose the [2] button to left of spreadsheet.
To return to normal Data --> [remove all] button lower left

data view

COUNT, COUNTIF, SUM, SUMIF

John Walkenbach has a fairly concise description and Examples for for some of these functions.  Suggest looking at  Tip 74:  Summing and Counting Using Multiple Criteria  before continuing.

SUMIF, COUNTIF, COUNT

 ABCD
1CheckedValue Formula in Column A comments
2w16   
3x4   
4y1   
5 32   
6x2   
76  =SUMIF(A2:A6,"x",B2:B6) simple formula
86  =SUMIF(A$2:OFFSET(A$7,-1,0),"x",B$2:OFFSET(C$7,-1,0)) simplifies insertion/deletion of rows
949  =SUMIF(A$2:OFFSET(A$7,-1,0),"<>x",B$2:OFFSET(C$7,-1,0))  
102  =MATCH("x",A$2:OFFSET(A$7,-1,0)) position in range
11x  =VLOOKUP("x",A$2:OFFSET(A$7,-1,0),1,FALSE) Found 1st column value
124  =VLOOKUP("x",A$2:OFFSET(C$7,-1,0),2,FALSE) found 2nd column value
133  =COUNTIF(A$2:OFFSET(A$7,-1,0),"<>x")  
142  =COUNTIF(A$2:OFFSET(A$7,-1,0),"x")  

SUMIF, SUMPRODUCT

These can be useful techniques.  This was from a posting by Stephen on 7Jul2000 in misc.
There are two easy ways:

=SUMIF(A1:A6,"Part#1",B1:B6)
=SUMPRODUCT((A1:A6="Part#1")*(B1:B6))

You could replace "Part#1" with a cell reference if you prefer.

The second construct is useful if you want to extend to more than one
condition:
=SUMPRODUCT((condition1)*(condition2)........*(number_range))
Note multiplying the conditions will result in a 1 or a 0, you will not see this technique in Help for SUMRRODUCT.

Tables with True, False, and COUNTIF

 ABCDEFGH
1TitlesPrice CountM.TotalsAMY ANNBOBSAL
2Music.A 5.00 2 10.00 TRUEFALSETRUE FALSE
3Music.B 6.25 3 18.75 FALSETRUETRUE TRUE
4Music.C 4.00 1 4.00 FALSETRUEFALSE FALSE
5Music.D 7.00 2 14.00 TRUEFALSEFALSE TRUE
6   846.75      
7c2 =COUNTIF(E2:L2,"=True")     
8d2 =B2*C2     
9         
10 Price CountM.TotalsAMY ANNBOBSAL
11Music.A 5.00 2 10.00 5.00 - 5.00 -
12Music.B 6.25 3 18.75 - 6.25 6.25 6.25
13Music.C 4.00 1 4.00 - 4.00 - -
14Music.D 7.00 2 14.00 7.00 - - 7.00
15   846.75 12.00 10.25 11.2513.25
16c11 =COUNTIF(E11:L11,">0")     
17c15 =SUM(C11:OFFSET(C15,-1,0))     
18d11 =B11*C11     
19d15 =SUM(D11:OFFSET(D15,-1,0))     
20e11 =IF(E2,$B2,0)     
21e15 =SUM(E11:OFFSET(E15,-1,0))     
The formulas shown are a result of GetFormula described on my Formula page.

COUNTIF and SUMIF formulas

 ABCDE
1Name DeptSalary  Dept.TotalDept.Total
2John Doe 01 A40,000   =IF(COUNTIF($B$2:B2,B2)<>COUNTIF(B:B,B2),"",SUMIF($B$2:$B$93,B2,$C$2:$C$93))
3John Doe 02A 60,000  (use fill-handle to replicate formula downward)
4John Doe 03A 70,000170,000  
5John Doe 07B 60,000  
6John Doe 08B 40,000  
7John Doe 11B 40,000140,000  
8John Doe 12C 60,000  
9John Doe 13C 60,000  
10John Doe 14C 40,000  
11John Doe 15C 70,000230,000  
12Total    540,000 =SUM(D$2:OFFSET(D12,-1,0))

Conditional Formatting

The key to using Conditional Formatting (C.F.) is to reduce a formula so that it indicates TRUE or FALSE (1 or 0).  C.F. overrides normal cell formatting.  You are limited to the use of three conditional formattings per worksheet (like three wishes).  C.F. began with XL97.  For XL95 you would have to write your own Event macros.

Some specific examples, as they appear in newsgroups:

These examples tell what to select before invoking Format --> Conditional Formatting and all are Formula is, and after coding your formula, choose your format (pattern and font color), the first you see without selecting a tab is the FONT.  When choosing an interior color you might also choose the borders because gridlines disappear with interior color and the borders chosen will only exist while C.F. is in effect.

To get smallest half (rounded up) of the entries in bold, change the formatting formula to
    =A1<=SMALL($A1:$T1,(COUNTA(A$1:T$1)+1)/2)

Consecutive Duplicates:  To compare value in column A with value below, but not include the difference being blank or empty.  Select ALL cells then enter the following conditional formatting formula: 
=AND($A1<>"",OR($A1=$A2,OFFSET($A1,-1,0)=$A1))

Duplicated Anywhere in Column:  Need not be sorted
    =COUNTIF($A:$A,$A1)>1

Conditional Formatting Formulas are considerably harder to show and find once used, unless you know which range to pick.  Each Conditional Format has a range that you can't just see, anyway the following is a start and will work best if it just has a formula, rather than "is less than" type of conditions.

Function CondFormula(myCell, Optional cond As Long = 1) As String
  'Bernie Deitrick programming 2000-02-18, modified D.McR 2001-08-07
  Application.Volatile
  CondFormula = myCell.FormatConditions(cond).Formula1
End Function
More information on Conditional Formatting

Sum of Visible Cells in a Range

The SUBTOTAL Worksheet Function will provide various totals or counts if the cells were hidden with a filter. The following will check for hidden rows and hidden columns to exclude them form the total.  The use of Volatile must be added and recalculatioin will only occur when Calculation happens (i.e.  F9).
Function VisibleSum(cellrange As Range) As Double
   Application.Volatile   'posted 2000-12-03, D.McRitchie, mod. 2002-02-12
   Dim cell As Range
   For Each cell In cellrange.cells
     If Not (cell.Rows.Hidden Or cell.Columns.Hidden) Then
		   If IsNumeric(Cell.Value) Then
         VisibleSum = VisibleSum + cell.Value
			 end if	 
     End If
   Next
End Function
The use of volatile in any functions used on any sheet can really slow things down.  Depending on your data, and what it is that you are hiding, you might be able to use SUMIF Worksheet Function, or SubTotals on the Data menu.  (see Summarizing Data, and Auto Filter (an Overview)

Related Areas


This page was introduced on July 4, 2000. 

[My Excel Pages -- home]    [INDEX to my site and the off-site pages I reference] 
[Site Search -- Excel]     [Go Back]    [Return to TOP

Please send your comments concerning this web page to: David McRitchie mailto:DMcRitchie@msn.com