Data Filtering and Subtotals

Analyzing part of the data

We have been working with various tables of data. We learned how to sort data alphabetically and from largest to smallest. This is all very useful and helpful. But what if you want to know the total or some other fact about a portion of the list? Spreadsheets are a great tool for doing exactly that!

Let’s look at a table of data about the 200 largest cities in the United States.

RankNameStatePopulation 2022Population 2020Growth %DensityLand Area Sq Mi
1New York CityNY893000288041901.41%29729300.381
2Los AngelesCA391997338987470.54%8359468.956
3ChicagoIL275654627463880.37%12124227.369
4HoustonTX234560623045801.75%3664640.194
5PhoenixAZ164064116081391.98%3169517.673
6PhiladelphiaPA161935516037970.96%12060134.279
7San AntonioTX145606914346251.47%3002485.113
8San DiegoCA140283813869321.13%4305325.877
9DallasTX132569113043791.61%3902339.736
10San JoseCA102670010132401.31%5774177.808
11AustinTX9961479618553.44%3114319.939
12JacksonvilleFL9751779496112.62%1305747.467
13Fort WorthTX9544579189153.72%2762345.584
14ColumbusOH9294929057482.55%4240219.197
15CharlotteNC9032118745793.17%2940307.238
16IndianapolisIN9010828876421.49%2492361.571
17San FranciscoCA8877118739651.55%1892746.903
18SeattleWA7626877370153.37%909583.862
19DenverCO7385947155223.12%4818153.292
20WashingtonDC7071096895452.48%1156661.136
21NashvilleTN7070916894472.50%1487475.543
22Oklahoma CityOK7012666810542.88%1156606.445
23BostonMA6872576756471.69%1421748.339
24El PasoTX6847536788150.87%2660257.42
25PortlandOR6662496525032.06%4994133.421
26Las VegasNV6535336419031.78%4610141.767
27MemphisTN630348633104-0.44%1986317.357
28DetroitMI624177639111-2.39%4500138.715
29BaltimoreMD578658585708-1.22%714980.947
30MilwaukeeWI573700577222-0.61%596596.184
31AlbuquerqueNM5683015645590.66%3036187.215
32FresnoCA5515955421071.72%4808114.725
33TucsonAZ5471315426290.82%2299238.014
34SacramentoCA5366355249432.18%549197.73
35Kansas CityMO5177505080901.87%1644314.886
36MesaAZ5173025042582.52%3746138.085
37AtlantaGA5144574987153.06%3790135.737
38OmahaNE5014694860513.07%3557140.983
39Colorado SpringsCO4914674789612.54%2520195
40RaleighNC4804194676652.65%3293145.886
41Long BeachCA4676384667420.19%922450.696
42Virginia BeachVA4637664594700.93%1895244.723
43MiamiFL4507974422411.90%1252435.996
44OaklandCA4506304406462.22%806255.893
45MinneapolisMN4394304299542.16%813854
46TulsaOK4172984130661.01%2113197.478
47BakersfieldCA4146494034552.70%2769149.758
48WichitaKS4005643975320.76%2478161.662
49ArlingtonTX4000323942661.44%417795.779
50AuroraCO3984973862613.07%2583154.272
51TampaFL3948093849592.49%3463114.017
52New OrleansLA3920313839972.05%2314169.434
53ClevelandOH367786372624-1.32%473477.694
54HonoluluHI3537063509640.78%584260.544
55AnaheimCA3489363468240.61%693450.32
56LouisvilleKY344794386884-12.21%1309263.434
57HendersonNV3295863176103.63%3107106.082
58LexingtonKY3279243225701.63%1156283.637
59IrvineCA3267303076705.83%497965.619
60StocktonCA3266243208041.78%525462.172
61OrlandoFL3214273075734.31%2907110.559
62Corpus ChristiTX3203933178630.79%2006159.703
63NewarkNJ3184313115492.16%1318924.144
64RiversideCA3172243149980.70%390481.258
65St. PaulMN3168193115271.67%609551.978
66CincinnatiOH3117913093170.79%400677.836
67San JuanPR311038322854-3.80%786839.533
68Santa AnaCA307367310227-0.93%1123427.361
69GreensboroNC3049092990351.93%2362129.068
70PittsburghPA302425302971-0.18%546155.376
71Jersey CityNJ3014192924492.98%2044414.744
72St. LouisMO298034301578-1.19%482761.744
73LincolnNE2976222910822.20%309396.223
74DurhamNC2945422835063.75%2625112.221
75AnchorageAK291131291247-0.04%1711706.8
76PlanoTX2906242854941.77%405471.682
77ChandlerAZ2839592759872.81%436065.124
78Chula VistaCA2818012754872.24%567749.641
79BuffaloNY2817572783491.21%697840.378
80GilbertAZ2798102679184.25%408668.475
81MadisonWI2771662698402.64%349379.339
82RenoNV2719532641652.86%2501108.744
83North Las VegasNV2716412625273.36%277198.015
84ToledoOH267603270871-1.22%332580.489
85Fort WayneIN2659262638860.77%2404110.636
86IrvingTX2647622566843.05%394867.06
87LubbockTX2626552571412.10%1950134.723
88St. PetersburgFL2610162583081.04%421961.864
89LaredoTX2590272552051.48%2450105.743
90ChesapeakeVA2548642494222.14%753338.51
91Winston-SalemNC2535312495451.57%1912132.614
92GlendaleAZ2526452483251.71%410261.592
93GarlandTX2498462460181.53%437957.06
94ScottsdaleAZ2461572413611.95%1338183.987
95ArlingtonVA2448472386432.53%941825.997
96EnterpriseNV2445012218319.27%478251.129
97BoiseID2416862356842.48%288883.674
98Santa ClaritaCA2391432286734.38%338070.755
99NorfolkVA237045238005-0.40%444953.275
100FremontCA2337882305041.40%301877.465
101SpokaneWA2330032289891.72%338968.759
102RichmondVA2310902266101.94%385659.923
103Baton RougeLA227066227470-0.18%262786.449
104San BernardinoCA2245372221011.08%361562.108
105TacomaWA2235362193461.87%449249.759
106Spring ValleyNV2230372155973.34%670733.253
107HialeahFL222797223109-0.14%1032421.581
108HuntsvilleAL2219862150063.14%1036214.363
109ModestoCA2219242184641.56%516442.977
110FriscoTX2172132005097.69%318868.125
111Des MoinesIA2162732141330.99%245388.18
112YonkersNY2146872115691.45%1191918.012
113Port St. LucieFL2129012048513.78%1786119.202
114Moreno ValleyCA2116882086341.44%413051.257
115WorcesterMA2116122065182.41%566437.36
116RochesterNY2114802113280.07%591335.766
117FontanaCA2108572083931.17%489543.072
118ColumbusGA2103302069221.62%972216.479
119FayettevilleNC2100892085010.76%1421147.847
120Sunrise ManorNV2088682056181.56%625833.376
121McKinneyTX2081461953086.17%310966.94
122Little RockAR2044052025910.89%1703119.992
123AugustaGA2033292020810.61%673302.274
124OxnardCA2028952020630.41%764826.528
125Salt Lake CityUT2023791997231.31%1828110.698
126AmarilloTX2023332003930.96%1989101.744
127Overland ParkKS2020121972382.36%268775.18
128Cape CoralFL2019581940163.93%1906105.948
129Grand RapidsMI2010931989171.08%449344.756
130Huntington BeachCA2004551987110.87%742327.003
131Sioux FallsSD2002431925173.86%256078.229
132Grand PrairieTX2002401961002.07%277172.255
133MontgomeryAL199571200603-0.52%1248159.882
134TallahasseeFL1991271961691.49%1982100.474
135BirminghamAL198433200733-1.16%1358146.076
136PeoriaAZ1983691909853.72%1127175.989
137GlendaleCA1975071965430.49%648230.471
138VancouverWA1967391909152.96%403648.744
139ProvidenceRI1935121909341.33%1051418.406
140KnoxvilleTN1931141907401.23%195698.713
141BrownsvilleTX1890821867381.24%1429132.322
142AkronOH188741190469-0.92%304861.933
143Newport NewsVA1873531862470.59%271668.992
144Fort LauderdaleFL1862081827601.85%538434.586
145MobileAL185427187041-0.87%1330139.465
146ShreveportLA185249187593-1.27%1725107.361
147ParadiseNV184852191238-3.45%395646.732
148TempeAZ1843611805872.05%461239.977
149ChattanoogaTN1837831810991.46%1286142.963
150CaryNC1826191747214.32%311058.725
151EugeneOR1807481766542.27%409544.138
152Elk GroveCA1807461761242.56%430042.033
153Santa RosaCA1801891781271.14%423842.519
154SalemOR1797151755352.33%369148.691
155OntarioCA1775331752651.28%355349.963
156AuroraIL177070180542-1.96%393445.009
157LancasterCA1768921735161.91%187694.281
158Rancho CucamongaCA1762891744531.04%439440.117
159OceansideCA1754641740680.80%425341.256
160Fort CollinsCO1749741698102.95%306057.182
161Pembroke PinesFL1744641711781.88%534032.673
162ClarksvilleTN1734801667223.90%175698.796
163PalmdaleCA1727901694501.93%1629106.076
164Garden GroveCA1721631719490.12%958817.957
165SpringfieldMO1711121691761.13%207782.392
166HaywardCA1667081629542.25%366145.537
167SalinasCA1661621635421.58%709223.428
168AlexandriaVA1633671594672.39%1093914.934
169PatersonNJ1624381597321.67%193088.413
170MurfreesboroTN1615711527695.45%261861.709
171BayamonPR161242165368-2.56%597726.978
172SunnyvaleCA1589491558051.98%721522.03
173Kansas CityKS1587711566071.36%1272124.815
174LakewoodCO1585841559841.64%368443.047
175KilleenTX1581291530953.18%289954.545
176CoronaCA1580881571360.60%395439.986
177BellevueWA1577521518543.74%471533.461
178SpringfieldMA1565031559290.37%491131.869
179CharlestonSC1562551502273.86%1413110.554
180HollywoodFL1555271530671.58%570327.269
181RosevilleCA1535691477733.77%348444.079
182PasadenaTX1525321519500.38%350043.586
183EscondidoCA1524641510380.94%408637.314
184PomonaCA1522451517130.35%662522.982
185MesquiteTX1521641501081.35%322047.252
186NapervilleIL1510781495401.02%389338.811
187JolietIL1509481503620.39%235364.152
188SavannahGA1500781477801.53%1444103.91
189JacksonMS149739153701-2.65%1348111.086
190BridgeportCT1495381486540.59%930916.064
191SyracuseNY1493101486200.46%596525.03
192SurpriseAZ1482741431483.46%1372108.063
193RockfordIL147811148655-0.57%229664.379
194TorranceCA1473931470670.22%718320.521
195ThorntonCO1464871418673.15%408135.891
196KentWA1454241365886.08%430933.75
197FullertonCA1453091436171.16%647822.431
198DentonTX1451671398693.65%150896.236
199VisaliaCA1447721413842.34%381737.924
200McAllenTX1446761422101.70%220265.698

You already know how to use the SUM() function to find the total of a range of cells. So you could easily find the total land area for all 200 cites. Or the total of any of the other columns. But let’s learn a very useful way to find the totals for individual states.

Create a new file

Let’s copy the table into a new spreadsheet file.

  • Start from the main office.com screen and click on the Excel icon
  • Then click on “New blank workbook”
  • In the green bar along the top, click on the default file name and rename it to “Filter and Subtotal”
  • Then copy the data from the table of information about the cities.
  • Paste it into your new worksheet.
  • Click on the little dialog that is usually on the right side towards the bottom and then choose “Paste Values”. This will remove the formatting from this web page and just pasted the plain values into the spreadsheet.
  • The easiest way to fix the column width is click on the upper left square of the grid to select all the rows and columns. Then double click the line between two columns and all the columns should autoresize to fit the information inside. If just the data is selected like it will be after you paste it in, it won’t work correctly. You need to select all the column as described.
  • If you like, you can give the sheet a better name by double clicking on the tab where it says “Sheet1” and giving it a more descriptive name.

If you need help, watch the video on the “Sorting” lesson.

Find a subtotal (the hard way)

Let’s find the total land area for the just cities in KS. This is often referred to as a subtotal. This is because it is a total of a subset, or portion, of the data.

First of all we can do it using ways we have already learned.

  • Sort the table by state. Refer the the “Sorting” lesson if needed
  • Add a SUM() function on the bottom of the “Land Area” column. Choose the three KS cities for your range value in the SUM() function. All three cities should be together because you sorted the table by state. Your formula should look something like this: =SUM(H94:H96).

Ok! Did you get a total of 361.657? If so, that worked great!

However, you will notice that this method requires you to manually change the range that you sum if you want to change which state you are analyzing. It’s just not as convenient as it could be.

If you re-sort the list by a different column you will notice a different problem. Try sorting by “name”. What happens to the total land area? It’s not totaling the Kansas cities anymore. It is still totaling the cells you asked it to but the cities from KS are no longer there.

So let’s learn a better way. First we will undo what we just did. Then we’ll learn how to filter the data to just show the part we are interested in. And then we’ll learn to use SUBTOTAL().

Undo your changes

Let’s get the table of data back to how it originally was. There are two methods of doing this. You can try whichever way you would like.

Method #1 – Using undo

  • On the “Home” menu ribbon, press the undo button enough times to undo everything your previous changes and return it to how it was right after you pasted the data into the sheet.

Method #2 – Manually change it back to how it was.

  • Sort the table by “rank” smallest to largest.
  • Delete the formula in the cell where you entered the SUM() function.

Filtering

All the major spreadsheet applications can selectively hide and show data. This is called filtering. Only data that matches the filter passes though and is shown. The data that does not match the filter is hidden. It is not deleted, only hidden, and will reappear when the filter is removed.

OK, time to practice!

  • Click on the “Data” menu ribbon if you are not already there.
  • Select a cell within the table of data
  • Click the filter button
  • Notice the dropdown arrows by each column heading
  • Click on the drop down for “State”
  • Uncheck the “select all” box
  • Scroll down as needed and select the checkbox for KS
  • Click apply

Watch the video if you need help.

Note how the row numbers for the hidden data are missing. They are hidden along with the data. The rows that are shown, in this case the rows with KS in the state column, retain their original row numbers.

Ok now remove the filter.

  • Click on the filter/dropdown arrow in the header of the “State” column
  • Click on Clear Filter from ‘State’
Remove Filter

Make the table a little nicer

Before we move on, let do a couple of things that will make it easier to use the table

  • Select the top row and apply bold formatting.
  • Select the entire sheet and double click on a column border to auto expand them to the correct width.
  • Click on the “View” ribbon and then click Freeze Panes -> Freeze Top Row

Watch the video if you need help.

Experiment with SUM() before learning about SUBTOTAL()

Now let’s experiment with the SUM() function. How does it work with filtered/hidden data?

  • Add a SUM() function with the correct range at the bottom of the data in the “Land Area” column. This will likely be something like: =SUM(H2:H201)
  • Click on the dropdown on the “State” column header again.
  • Select a state of your choice.
  • Was the total hidden along with the other rows? Excel tends to hide the next couple of rows on the bottom of the data along with the other rows.
  • To see everything again, remove the filter again.
  • Enter a SUM() function three or more rows below the data.
  • Try filtering the “State” column again.
  • Observe the total below the “Land Area” column. It should not be hidden this time. Notice that it doesn’t change. That is because all the rows are still there. We noticed earlier that the row numbers are missing when rows are hidden. They are hidden but still exist so the SUM() function is doing exactly what we told it to do. It is adding all the rows together in your range regardless if they are hidden or not.

In this case, this isn’t what we want to happen. We want to know the total for just the filtered rows. SUBTOTAL() works really well for this.

Using SUBTOTAL()

This function is quite flexible and useful. It can be used to find the total, or the average, or smallest, or the largest, and a number of other things in a column of numbers.

Let’s jump right in.

  • Enter a SUBTOTAL() function right below the data in the “Population 2022” column. You don’t need to worry about putting it three rows down. Excel will not hide this formula.
  • SUBTOTAL() takes two pieces of information. The type of calculation you want to do. And the range on which you wish to perform the calculation.
  • As you start to type in the function you will see a link for more information. Click on this to see what number you should use to sum the range and ignore the hidden rows. You will see that you need to use 109.
  • Then enter the range.
  • When you are finished your formula should look like this: =SUBTOTAL(109,D2:D201)
  • Now you can filter by any state you wish and the subtotal will show you the population for just the filtered cities!

This may be a lot easier to follow by watching the video.

Adding a Subtotal

Congratulations! Now you know how to find the subtotal for filtered information.

To finish up:

  • Add a subtotal to the “Population 2020” column just like you did on the “Population 2022” column.
  • Do the same on the “Land Area” column. Delete the SUM() you did earlier if you haven’t already done so.
  • On the “Growth %” and “Density” columns add a subtotal for the average. You will need to click on the more information link to see which number to use.
  • Format the bottom row of totals bold so they stand out a little more.

When you are finished it should look a lot like the photo at the top of this lesson. In the photo the data has been filtered to just show cities in KS.

Great job!


Comments

Leave a Reply