Ravindra BagaleCourses & study guides मराठी Track your progress

6. Tables, Sorting and Filtering

Excel

6.8 The Subtotal Feature

Turn an order list into a report people can expand

The fictional Konkan Fresh Mart afternoon lead wants to see the amounts for Aundh, Baner and Wakad on one screen. On a busy day they may also need to expand Baner and check which order contributes a larger amount. Keeping a detailed order list and hand-typing a separate sum for each area gives the lead two places to update. A Subtotal command in desktop Excel can make a report copy where each group of related rows has a calculated summary, and the details can be shown or hidden using controls at the edge of the worksheet.

This lesson uses a made-up shop and a later dispatch scenario inspired by shopping through Blinkit and Amazon Now. All orders, amounts, reporting rules and decisions in the examples are fictional. A “group” here means a consecutive block of source rows with the same value in a selected field. The Subtotal command inserts actual worksheet rows at the ends of those blocks when you choose summaries below the data. It writes formulas into the new summary rows and builds an outline. An outline is the set of controls used to collapse or expand those related rows.

Sort complete records before adding group totals

The Subtotal dialog asks for a heading in a control labeled At each change in. This describes how it scans the list. If Area reads Aundh, Baner, Aundh across three rows, it encounters a change twice. The two Aundh blocks will each receive a subtotal. If the assignment expects exactly one report line for each area, make every area’s source records adjacent first.

An interleaved Aundh, Baner, Aundh order creates two Aundh blocks. Sorting complete records brings Aundh rows together and their 300 and 260 amounts total 560.
Excel recognizes changes between adjacent values. A full-record sort is what makes the two Aundh records one group.

Make sure every field travels with its order

  • Start from a complete rectangle. Use one heading row and consistent fields from the first order through the last. Remove section separator rows or columns on the report copy so the intended record list is continuous.
  • Sort the list by its future group heading. Open the sort dialog on the whole block with heading detection correct. Choose Area for the first lab or City for the second. If Excel offers to expand a single-column selection, preserve the complete row relationship.
  • Verify one misplaced record by ID. A full record includes the order’s ID, assigned area and its original amount. If you sort only Area cells, a different area can become attached to an existing order. The new output can still look neat while all the area totals are wrong. Check an original ID and amount after sorting.
  • Add the inner sort before making a nested report. For figures broken down by City and Platform, sort City first and Platform second. That keeps each city together, then keeps all orders of one platform together inside that city. Two labels that happen to appear on multiple platforms do not create a valid grouping unless each expected block is adjacent.
  • Keep a way back to the original row order. Copy the source first or add an Import sequence field before sorting. The Remove All command removes subtotal and outline rows. It does not undo the separate sort you did before inserting them.

Choose the calculation and layout in the dialog

Use desktop Excel with the Subtotal command available under Data → Outline. Microsoft documents the command for ordinary ranges. An Excel Table already supplies features like a Total Row, and the Subtotal command is unavailable inside it. Keep the master Table if its named columns or calculated columns are used elsewhere. Make a separate normal-range copy for this lesson, or convert a Table only on a scratch copy you understand. In clients without this command you can still build and verify group totals separately from the source using a PivotTable or formulas.

Read the dialog controls as separate choices.
ControlChoice for Lab 1Effect
At each change inAreaEnds a block when the Area value changes.
Use functionSumAdds numeric amounts within each group.
Add subtotal toAmountPlaces the summary in the Amount column.
Summary below dataCheckedShows the summary below each detail block.
Replace current subtotalsKeep for first runOn a later run, choose whether earlier groups and functions should be retained.
Page break between groupsUncheckedOptional separation for a print-oriented report.

Separate the three Excel features with similar names

A Table Total Row is a one-row summary inside an Excel Table. It can use SUBTOTAL formulas and follow the Table’s active filter. A SUBTOTAL formula you type yourself calculates a selected statistic from a reference without inserting group rows. The Subtotal command creates a series of subtotal formulas plus a grand total and outline on an ordinary range. For a printed report with totals under each city and collapsible detail, the command fits the task. A Table Total Row is enough for a single grand or visible total, and a PivotTable can produce a rearrangeable group summary from a separate existing source.

The command’s summary function should describe the intended value rather than merely produce a number in an empty cell. Sum suits rupee amounts. Count in the dialog can support a record count when the selected field is always filled, and Count Numbers is the operation for numeric observations in clients that show that choice. Check exactly which formula Excel wrote after using a counting operation. A missing amount can change one kind of count and leave the ID count unchanged. An average duration needs valid numeric observations and a unit such as minutes.

Lab 1. Build and check the area report

Enter this independent six-order exercise on a sheet called Area Source in an Excel practice workbook. Use only the normal grid, with A1:C7 occupied and no other section next to it. Amount cells are numbers. The rows are intentionally interleaved so you can see the difference between the order in which transactions arrived and the order a grouped report needs. Duplicate the tab to a scratch report named Area Report.

Source A1:C7. Preserve the original ID, Area and Amount association when sorting.
Order IDAreaAmount
KFM-801Aundh300
KFM-803Baner780
KFM-802Aundh260
KFM-806Wakad640
KFM-804Baner910
KFM-805Baner420

Predict the wrong and the right number of groups

Before touching the report, follow its Area values from top to bottom. The two Aundh orders are separated by the first Baner order. The first Baner order is also separate from the last two. The adjacent groups as entered have totals 300, 780, 260, 640 and 1,330. If you inserted subtotals in this state you would get five groups for three area names. The grand total would still add up. Count of distinct groups and number of inserted group rows are therefore separate checks.

  1. Sort the source on the copy. Select the entire A1:C7 block on Area Report and open the sort dialog. Sort first by Area A to Z and then by Order ID A to Z to make the example order repeatable. Confirm the final ID sequence 801, 802, 803, 804, 805, 806, with the full KFM prefix in the sheet. Check KFM-802 still has ₹260 and belongs to Aundh.
  2. Add the area subtotal rows. Click a data cell on Area Report. Open Data → Outline → Subtotal. Choose Area for At each change in, Sum for Use function and Amount under Add subtotal to. Select Summary below data, leave page breaks off and confirm. Excel inserts three area summaries and a grand total.
  3. Inspect the exact group totals. The Aundh amount is ₹560, Baner is ₹2,110 and Wakad is ₹640. Add those amounts and obtain ₹3,310. To confirm the Baner subtotal, expand that area and verify 780 + 910 + 420 = 2,110. Check each subtotal’s position below its last detail record.
  4. Check the grand calculation. In this fresh run on A1:C7 with summaries below data, the two Aundh details occupy rows 2 and 3, followed by a summary. Baner and Wakad then supply their details and summaries. Inspect the grand formula that appears below them. It is a SUBTOTAL calculation over the detail portion of the range that already contains group formulas, which it can skip as nested subtotals.
  5. Compare with an independent reference. On a separate check tab, sum the six source amounts from Area Source. The result is ₹3,310. An ordinary SUM written over all report detail and area summary amounts, excluding the grand total, would give ₹6,620 because each area’s amounts were counted twice. Reconcile the report to the source before using it elsewhere.

Use outline levels to inspect the report at three depths

For the single grouping in this lab, select 1 in the outline to show the grand total. Select 2 to show three area totals as well as the grand total. Then choose 3 to see all six order rows in addition to the summary rows. The heading row stays available. The plus and minus buttons for an individual group let you open Baner while keeping the other areas collapsed. These states change what you can see, while the report keeps both the detail and subtotal rows.

One-level area outline. Level 1 shows grand total, level 2 shows three area totals and grand total, and level 3 also shows all six orders.
Choose the broad result, each area’s result or the full details from the same outlined sheet.

Switch the report between different depths

  1. Check the sorted records

    801 and 802 belong to Aundh, 803 through 805 to Baner, and 806 to Wakad. Their six amounts total ₹3,310.

  2. Insert a group summary wherever Area changes

    Aundh gets ₹560, Baner gets ₹2,110, and Wakad gets ₹640. The command also inserts an overall detail total of ₹3,310.

  3. Select outline level 2

    Read the three area totals and overall total with all six order details collapsed.

  4. Expand Baner

    Use the individual plus control to find the three original order IDs, then recompute the Baner amount from those details.

Remove the extra report rows and test a different statistic

When ready to replace this particular report, use Data → Outline → Subtotal and choose Remove All. Verify six order rows, with the original values in their sorted order. Compare IDs 801 and 803 with the original tab. The command leaves the records sorted because you sorted before inserting the subtotal rows. Remove All also removes the outline and page breaks inserted with these subtotals.

As an independent run, choose Average instead of Sum for Amount in the same sorted list. Aundh averages ₹280 from two records, Baner averages ₹703 and one third from three and Wakad averages ₹640 from its one record. The grand average is ₹3,310 divided by six, about ₹551.67. Averaging those three area averages with equal weight would give about ₹541.11. A group with three orders should contribute three order observations to an all-orders average. Excel’s grand result uses detail rows, so groups with different counts do not get identical weight. Remove this test report before beginning the nested exercise.

Lab 2. Add platform totals inside the city report

The grocery dispatch example needs a city total for afternoon staffing. Inside each city the coordinator also wants to compare the amounts carried by two delivery channels. “Pune total” and “Pune’s Blinkit amount” should both be available, along with the orders contributing to each. A nested outline gives the reader those layers in the same report copy. A nested group is an inner group whose records are part of a single outer group. In this report Platform is the inner field and City is the outer field. The city total includes every platform within that city.

Enter the dispatch records in A1:D11 on a separate scratch sheet. All amounts are practice rupee amounts.
Order IDCityPlatformAmount
BLK-1001PuneBlinkit64
BLK-1002NashikBlinkit270
AMN-1003PuneAmazon Now110
BLK-1004NagpurBlinkit240
AMN-1005KolhapurAmazon Now232
BLK-1006PuneBlinkit150
BLK-1007SolapurBlinkit1299
AMN-1008Sambhaji NagarAmazon Now195
BLK-1009PuneBlinkit220
BLK-1010NashikBlinkit90

Build the outer group, then add the inner group

  1. Sort the raw records before either subtotal pass. Select all four fields and use a multi-level sort with City A to Z, then Platform A to Z, then Order ID A to Z. Verify Pune’s first order on this sorted list is AMN-1003 at ₹110. The three other Pune IDs follow in its Blinkit block, which will be a single platform subgroup.
  2. Insert the city totals. On the sorted report copy open Subtotal. Choose City, Sum and Amount with summary rows below the data. Expect six city groups. The checksum is still ₹2,870, the total of the ten source amounts. Keep this city summary in the report before beginning the next pass.
  3. Add the platform totals within each city. Run the command again, now with Platform as the change field and Sum on Amount. Clear Replace current subtotals so the city summaries stay. The report was already sorted at both levels before adding any extra rows. Sorting the mixed detail and subtotal rows at this step would change the report’s structure.
  4. Inspect Pune as a controlled example. The Pune Amazon Now amount is ₹110. The Pune Blinkit amount is ₹434 from ₹64, ₹150 and ₹220. Together they make Pune’s unchanged city total ₹544. A single-platform city such as Nashik may show the same amount on its city and platform summary lines. Those lines describe two levels of the same detail, not twice as much sales activity.
  5. Verify the final result against the independent source. The grand total should stay ₹2,870. Check the original ID count of 10 against the source rather than counting all report rows. If you want the count of details from the report, first inspect an expanded city and account separately for synthetic summary rows.
Expected group amounts. Treat each column as its own check.
CityAmazon Now amountBlinkit amountCity amount
Kolhapur232No orders232
NagpurNo orders240240
NashikNo orders360360
Pune110434544
Sambhaji Nagar195No orders195
SolapurNo orders12991299

Read a nested report in one direction at a time

At the broadest view you can check the grand amount. Expand to see city totals, then the platform subtotals, then source order rows. In the standard nested layout this adds a fourth outline depth. Use individual controls to expand Pune if you only need one city. Compare the city’s IDs with the amounts in the table. When reading a worksheet on a small screen, its outline can keep a long list compact while letting you look up one exception.

If someone asks for the sum of platform amounts across all cities, start with the intended measure. The source Platform column represents a category across the whole list, which a separate PivotTable or calculation can summarize directly. The nested report can also be read at the platform level, but you would need to identify all platform subtotal rows and exclude city totals. Adding every amount displayed at the broadest visible level is unsafe if those lines include both a parent with its full children and the children themselves.

Compare a working report and a summary snapshot

Keep exact evidence when sharing only the outline summaries

When someone wants three area totals and a grand total as a small handoff, collapse Area Report to level 2 and copy only the visible cells into a separate scratch output on a client that offers that selection. On desktop Windows, choose the source block and use Home → Find & Select → Go To Special → Visible cells only. Follow the available commands on other clients. The web does not provide this select-visible-only operation for an ordinary range, so do not assume a collapsed normal range will paste only the four total rows. You can instead enter the checked totals into a clean output or produce the copy in the desktop app. Before relying on the output, open it independently and check all four row labels and their values.

If you intend the extract as a static record of a particular report, choose the values paste option as appropriate so references to the source sheet do not need to work in the new destination. Record whether formulas were retained and which date or input version the amounts describe. A clipboard copy can mean you see the group rows because the current outline is collapsed, while the underlying individual order rows are still present. Inspect the resulting sheet with no outline or filters active before giving it to the next reader.

Update amounts and group membership in the right place

With automatic calculation active, changing the source values referenced by existing formulas on the report copy can update their summary results. For example, change KFM-806 from ₹640 to ₹700 in a scratch report copy. The Wakad subtotal becomes ₹700 and grand amount becomes ₹3,370. The master source is unchanged. Restore ₹640 before comparing it to the original controls again. A new delivery or a change to a grouping value can alter the actual group boundaries. Rather than placing an order below an already-inserted summary and assuming it belongs, rebuild the report from an updated clean source, sort it and verify its totals and group membership.

On a workbook that receives new records each day, the repeated source and report arrangement is the main decision. A master Table holds the detail. A separate PivotTable can be refreshed against the correct source for an ongoing report. A static Subtotal command snapshot can support a periodic review where you want collapsed or expanded group rows. When someone asks for the full set of details in an export, select the clean master area and its record fields. Keep summary rows out of an export intended to contain one row per order.

Use controls that detect grouping mistakes

Show why an unchanged grand total can hide a broken sort

Imagine someone takes the six displayed Area values from the first practice list, sorts those labels separately and pastes them back into column B while leaving the IDs and amounts in their original positions. This is a thought experiment, so keep the actual exercise worksheet intact. The resulting labels are Aundh, Aundh, Baner, Baner, Baner, Wakad. They look perfectly sorted. The sorted labels are now attached to the wrong set of rows.

  • The two amounts under Aundh become ₹300 and ₹780, totaling ₹1,080. The second belongs to KFM-803, originally a Baner order. The correct Aundh amount is only ₹560.
  • The following Baner block now contains ₹260, ₹640 and ₹910, totaling ₹1,810. The original ₹260 is Aundh and ₹640 is Wakad. The correct Baner amount is ₹2,110.
  • The final Wakad line now contains ₹420, originally a Baner order. Wakad’s correct practice amount is ₹640.
  • The new incorrect group totals still add to ₹3,310. No amount cell was removed. A grand reconciliation alone cannot identify the changed association between order and area.

Protect the association by selecting and sorting whole records. Check a few ID-to-field pairs before and after the sort. Reconcile each group to its independently identified original records. In a larger source you can use a separate conditional sum by Area on the clean source to verify the command’s output. Pick at least one record that would have changed its group under the mistaken sort. A value chosen from the unchanged first row is a weak check because it could match both designs.

Keep a time group specific enough to verify

Sometimes an area report later needs monthly totals. A cell may look like “Nov” because it uses a date format while holding a complete date. The command identifies differences in stored group values. Several dates in November still belong to separate day values. Add a Month key on a clean practice copy using the first calendar day of each month, such as =DATE(YEAR(B2),MONTH(B2),1) when B2 is the date of the first data record. Format the key to show year and month, and sort by that key before subtotaling. This makes 2 November and 8 November 2026 belong to the same month group while retaining the original date in a different field.

For a reading check, consider three fake dates and amounts: 2 November 2026 at ₹270, 8 November 2026 at ₹90, and 2 November 2027 at ₹130. Year plus month yields groups worth ₹360 and ₹130. A rule based only on the month label could put all three under November at ₹490. The monthly grand total is unchanged. Choose clear period labels that someone opening the report months later can still interpret.

Verify an inserted row’s position before repeating the workflow

In the first exercise, the group amount appears below each detail block because Summary below data is selected. A report reader sees the line items first and the resulting amount afterward. If you choose the placement above the data on another scratch copy, Excel uses summary rows above the related detail instead. Both layouts can be correct. Test the expected association visually by opening the Aundh group and verifying which report row summarizes KFM-801 and KFM-802. A total in a different row location may matter to a document that expects a fixed cell address.

Before rebuilding a periodic report, record the grouping order, summary placement and required checks. For the simple practice report your notes can say “Area A to Z, then Order ID; Sum on Amount; summaries below; three groups; six details.” For the nested case use “City, Platform, Order ID; city first; preserve city totals on platform pass.” The notes give your colleague the choices that affect row layout rather than only the final grand number. If a future version replaces the source, verify the new number of groups and the meaning of its dates instead of insisting it should always show three areas or six cities.

Try an order that creates a genuinely new group. On another clean copy append KFM-807 in Pashan at ₹350 and rebuild from the seven source rows. A to Z places Pashan between Baner and Wakad. Level 2 should now show Aundh at ₹560, Baner at ₹2,110, Pashan at ₹350, Wakad at ₹640 and a grand total of ₹3,660. When you expand Pashan, verify it contains the one new ID. If the new amount is included in the grand total while a Pashan line is missing, inspect the group heading and sort order. This is a structural test rather than only a change in the size of a total.

When you need line breaks for a printout, the command’s optional page breaks separate the groups. Keep that choice off in the initial labs. In a report copy made for printing, review the print preview and check that the page heading still communicates the group and amount unit. Page breaks concern the reading layout. Reconcile the group values from the workbook first so that a clean printed page does not become the only evidence for its numbers.

Diagnose the report from one known order

Use source membership as the first control

  • The same city has several totals. Expand the entire report and check whether the same city’s details arrived in separate blocks. Start again on clean records, sort the complete block by City and then insert totals once. Keep ID, city and amount associated during the sort.
  • A platform subtotal is missing or sits outside a city. Look at the pre-group sort and the order of the two commands. City is the primary key and its summaries are added first. Platform is the secondary key and its summaries are added after preserving the existing city summaries.
  • The command is unavailable. Check your Excel client and whether you are inside an Excel Table. The ordinary-range worksheet command and the Table’s summary controls belong to different features. Use a clean range on a desktop client that offers the command for these labs.
  • A group total seems to have disappeared. Expand the outline and clear source filters in the practice copy. Microsoft documents that filtering a list containing inserted subtotal rows can hide those rows. Inspect the complete report before concluding an inserted group was removed.
  • The amount looks several times too big. Find out whether the reference contains city summaries and platform summaries as well as the detailed orders. Reconcile to the clean source or use a verified subtotal-aware operation. Check the selected range excludes the overall total when you perform the demonstration that deliberately double counts.
  • Remove All left the list in a different order. Compare the remaining detail IDs with the original source rather than the original row positions. The earlier sort still applies. Restore by using a captured import sequence or starting from the untouched source again.

Test a second statistic without replacing the report

To reproduce the baseline lesson’s Count exercise, run the Area Sum report again from the same clean six sorted records. Run Subtotal a second time for Area with Count as the function, choose a nonempty detail field such as Order ID, and clear Replace current subtotals. In the three area blocks you should find counts of two, three and one respectively. The overall count of detail records is six. Verify which field the Count formula references. If you subtotal Amount instead, a future record with an unavailable amount can affect a count based on that field. The report still needs a count definition that matches the stated purpose.

In the second run, never assume a currency-formatted cell labeled Count should be read as a number of rupees or that all summary lines for the same group can be added. A group can have a quantity count, a currency sum and an average duration. To share a compact summary, explicitly arrange those results in separate labeled columns and independently check the source numbers. The count and amount can then both describe Baner without being mistaken for measurements of the same kind.

Quiz. Predict the report before building it

Area reads Aundh, Baner, Aundh. How many Aundh subtotals does the command add?

Two. Each Aundh block ends before a different value or before the end of the list. A full-record Area sort brings the matching values together first, giving one Aundh summary.

Which field belongs in Add subtotal to for a rupee summary by Area?

Amount is the field to sum. Area belongs under At each change in and identifies the boundaries. The numeric subtotal goes in the Amount column for each area.

Which rows should you see at level 2 of the first exercise?

The Aundh, Baner and Wakad subtotals and the grand total remain visible, along with the heading row. The six detail orders are collapsed. Expand one area to see its contributing IDs.

Why does an all-orders average differ from the average of the three area averages?

The areas have different numbers of orders. All six order amounts contribute one observation each to the grand average of about ₹551.67. Averaging the three group summaries would assign each area equal weight.

What if Replace current subtotals remains selected for the Platform pass?

The new command can replace the city subtotals. To add inner platform summaries while preserving the outer city blocks, start from the source sorted by City and Platform and clear that option for the second pass.

Does Remove All restore the original transaction arrival order?

It removes the inserted subtotal rows and the outline and page breaks created with them. It leaves the detail rows in their current order. A saved copy or a source sequence field is needed if you want to recover arrival order.

Interview practice. Explain what a grouped report contains

When choose the Subtotal command over a Table Total Row?

Use the command on a normal range when each adjacent category needs a subtotal row and people should expand its underlying records. Use the Table Total Row for a summary within the Table without inserting summaries between each city’s orders.

Why does the sum of every displayed amount overstate some reports?

One displayed amount can be a city subtotal that already contains the platform subtotals. Adding every line can count the same detail multiple times. Identify the intended level or calculate the measure directly from the clean order list.

How can you prove the result kept complete records together during the sort?

Compare an ID, area and amount from the sorted report with the original order row. For example, KFM-802 belongs in Aundh at ₹260. Check both group count and the sum from those known detail IDs. A correct grand total alone cannot detect disconnected area labels.

How would you send just the three area totals and grand total for review?

Collapse the report to the appropriate level, use the available visible-cells selection on desktop and paste a verified copy in a clean destination. Check labels, values and row count where nothing is hidden, and choose a value snapshot if the report should remain independent.

A new order arrived after creating the grouped report. How should you handle it?

Update the clean source and rebuild the appropriate report from that source. Sort by the group fields, apply the subtotal settings and compare IDs and amounts. Editing an existing amount can recalculate a formula, while new records can require different group boundaries.

Revision cards

  • At each change. A new group begins when the sort field changes. Sort full records by that field first.
  • Choose separate controls. Group by Area, choose Sum and add the result to Amount.
  • Levels. One grouping usually gives grand total, group summaries and all detail levels.
  • Nested report. City first in the sort and in the command. Platform next, preserving the existing subtotals.
  • Grand average. Read every detail observation. Areas with different counts should have different weights.
  • Remove All. Removes inserted subtotal structures and leaves the sorted details available.

Microsoft references