LearnFinance
← Spreadsheets & Python for Finance Lesson 2 of 6 · 16 min · +50 XP
Spreadsheets & Python for Finance · Lesson 02

Tables, lookups and pivots: shaping real financial data

Most finance work starts with messy lists: transactions, holdings, invoices, prices. How to store data as proper tables; valuing a portfolio with XLOOKUP, step by step; approximate-match lookups for tax slabs, with a 2026-27 new-regime calculator and marginal relief worked through; SUMIFS and pivot tables on a bank statement; the 2020 case where a spreadsheet's row limit lost 16,000 COVID test results; and the lookup errors that quietly corrupt models.

Facts reviewed Oct 2026

Before any analysis, data has to be organised. A broker’s contract notes, a bank statement, a list of invoices, a fund’s holdings: they all start as messy lists.

Spreadsheets have powerful tools for shaping such data. Knowing them saves hours every week. This lesson covers the essentials, with formulas that work in Excel and, with small differences, Google Sheets.

Store data as a table

Good analysis starts with tidy data:

  • One row per record (one transaction, one holding, one day). One column per field (date, amount, category).
  • A single header row. No merged cells, no blank rows, no subtotals mixed into the data.
  • Consistent formats. Real dates, not text that looks like a date. Numbers, not numbers stored as text.

In Excel, Format as Table (Ctrl+T) turns a range into a structured table. It grows automatically as you add rows. And formulas can refer to columns by name, such as =SUM(Trades[Amount]).

Lookups: pulling values from another table

A lookup finds a value in one table and brings back a matching value from another.

Worked example: valuing a portfolio. Your Holdings table lists tickers and quantities. A Prices table lists tickers and today’s prices.

Holdings: TickerQuantity
INFY50
TCS20
HDFCBANK40
  1. In a new Price column, next to INFY, enter: =XLOOKUP(A2, Prices[Ticker], Prices[Price], "Not found").
  2. What it does: it looks for “INFY” in the Prices table’s Ticker column, and returns the price on that row. If there’s no match, it shows “Not found”.
  3. Value column: =B2 * C2, quantity × price.
  4. Fill down for every holding, then =SUM(Holdings[Value]) gives the portfolio’s value.

(Real companies here are just examples of tickers, not suggestions.)

Three ways to look up:

  • XLOOKUP (Excel 2021/365, Google Sheets) searches one column and returns from another, with an optional value if nothing matches.
  • INDEX-MATCH does the same in older versions: =INDEX(Prices[Price], MATCH(A2, Prices[Ticker], 0)).
  • VLOOKUP is common but fragile. It breaks if columns are inserted. And by default it does an approximate match, which silently returns wrong values for unsorted text. Always ask for an exact match (FALSE or 0) when matching names or codes.
Quick check

A VLOOKUP of stock names returns a price for the wrong company, with no error. What's the most likely cause?

Approximate match: slabs and rate cards

Approximate matching is exactly right for bands: tax slabs, commission tiers, interest-rate cards. Sort the thresholds from smallest to largest. An approximate lookup then returns the rate for the highest threshold at or below the value:

=XLOOKUP(income, Slabs[From], Slabs[Rate], , -1)

Here -1 means “exact match, or the next smaller item”.

The new-regime slabs for 2026-27

Under the new tax regime for 2026-27 (unchanged from 2025-26), income is taxed in ₹4 lakh steps:

Taxable incomeRate
Up to ₹4 lakh0%
₹4–8 lakh5%
₹8–12 lakh10%
₹12–16 lakh15%
₹16–20 lakh20%
₹20–24 lakh25%
Above ₹24 lakh30%

A rebate makes tax nil up to ₹12 lakh of taxable income, with marginal relief just above it. A 4% cess applies on top. (As of October 2026; Personal Finance explains the choice between regimes.)

Worked example. Taxable income of ₹18 lakh.

  1. Marginal rate: the lookup finds the highest threshold at or below ₹18 lakh: ₹16 lakh, so 20%.
  2. Tax, slab by slab: ₹0 on the first ₹4 lakh. Then 5% of ₹4 lakh = ₹20,000. 10% of ₹4 lakh = ₹40,000. 15% of ₹4 lakh = ₹60,000. 20% of the last ₹2 lakh = ₹40,000.
  3. Total: ₹20,000 + ₹40,000 + ₹60,000 + ₹40,000 = ₹1,60,000.
  4. With 4% cess: ₹1,60,000 × 1.04 = ₹1,66,400.
  5. Average rate: ₹1,66,400 ÷ ₹18 lakh = about 9.2%, far below the 20% marginal rate.
A slab lookup: new-regime income tax for 2026-27
Marginal rate (approximate-match lookup)
20%
Tax from the slabs, before rebate
₹1.6 L
Tax after rebate and marginal relief
₹1.6 L
Tax including 4% cess
₹1.66 L
Average tax rate
9.24%

Resident individual, new regime, ignoring surcharge and special-rate income such as capital gains. The defaults: a 20% marginal rate and ₹1.6 lakh of tax, about ₹1.66 lakh with cess, an average rate of about 9.2%.

Summarising: SUMIFS and pivot tables

SUMIFS adds up values that meet several conditions. COUNTIFS and AVERAGEIFS work the same way.

Worked example: a bank statement. Your table Txns has columns Date, Category and Amount (spending as positive numbers).

  1. Total food spending: =SUMIFS(Txns[Amount], Txns[Category], "Food").
  2. Food in March 2026 only: add two date conditions: =SUMIFS(Txns[Amount], Txns[Category], "Food", Txns[Date], ">=1-Mar-2026", Txns[Date], "<1-Apr-2026").
  3. Number of UPI payments above ₹2,000: =COUNTIFS(Txns[Mode], "UPI", Txns[Amount], ">2000").

A pivot table does this for a whole table at once. You drag fields into rows, columns and values:

  1. Rows: Category. Columns: Month. Values: Sum of Amount.
  2. Result: a grid of spending by category and month, built in seconds. Refresh it when new rows arrive, and double-click any cell to see the transactions behind it.

Typical finance uses: a monthly cash-flow summary, portfolio exposure by sector, unpaid invoices by customer and age, and realised gains by financial year for tax.

A real case: the spreadsheet that lost 16,000 test results

In October 2020, England’s public health agency found that nearly 16,000 positive COVID-19 test results had gone unreported for about a week. The cause was a spreadsheet.

Test labs sent results as data files. These were loaded into Excel in the old XLS format, which holds only about 65,000 rows. When a file had more rows than that, the extras were simply cut off, with no error. Thousands of people who had tested positive weren’t contacted in time.

The lesson for finance: tools have limits, and they often fail silently. Always check that row counts and totals match between the source data and your sheet.

Lookup and data errors to avoid

  • Trailing spaces and numbers stored as text. “INFY ” won’t match “INFY”. TRIM and VALUE clean them.
  • Duplicate keys. A lookup returns only the first match. Check uniqueness with COUNTIF.
  • Hard-coded ranges like A2:A500 that don’t grow with new data. Use tables.
  • Errors hidden by IFERROR. Hiding #N/A hides missing data. Flag it instead.
  • Dates read as text, or text read as dates. Spreadsheets sometimes “helpfully” convert codes that look like dates.

Going further: why XLOOKUP’s approximate match needs sorted data, and how it’s so fast. For an approximate match, the spreadsheet can use a binary search. It looks at the middle of the sorted list, decides whether the value is above or below, throws away the wrong half, and repeats. With a million rows, that takes only about 20 steps (2²⁰ is about a million), instead of up to a million checks. But binary search only works if the list is sorted. On an unsorted list, it confidently returns a wrong row. That’s the same failure as VLOOKUP’s default on unsorted text. If you can’t guarantee sorted data, use an exact match.

Common mistakes

  • Using VLOOKUP’s default on names or codes. Ask for an exact match, or use XLOOKUP.
  • Messy data: merged cells, subtotal rows, blank rows. Keep one record per row.
  • Treating the marginal rate as the average rate. At ₹18 lakh, the average is about 9%, not 20%.
  • Hiding errors with IFERROR. You lose sight of missing matches.
  • Not checking totals. Row counts and sums should match the source.
Practice 1: What tax applies on a taxable income of ₹12.5 lakh under the new regime?
  1. Slab tax: ₹20,000 + ₹40,000 + 15% of ₹50,000 = ₹20,000 + ₹40,000 + ₹7,500 = ₹67,500.
  2. Marginal relief: tax can’t exceed the income above ₹12 lakh, which is ₹50,000.
  3. So the tax is the smaller figure: ₹50,000, or ₹52,000 with cess.

Enter 1250000 in the calculator to check. Just above ₹12 lakh, each extra rupee is taxed in full until the slab tax takes over.

Practice 2: Write a formula for the total amount you invested in mutual funds in FY 2025-26, from a table Txns with columns Date, Type and Amount.

=SUMIFS(Txns[Amount], Txns[Type], "MF purchase", Txns[Date], ">=1-Apr-2025", Txns[Date], "<1-Apr-2026")

  1. First condition: only rows where Type is “MF purchase”.
  2. Second and third: dates from 1 April 2025 up to, but not including, 1 April 2026: the financial year.

Key takeaways

  • Keep data tidy: one row per record, one column per field, real dates and numbers. Use tables.
  • Use XLOOKUP or INDEX-MATCH for exact lookups. Avoid VLOOKUP’s default approximate match on text.
  • Approximate match suits slabs and rate cards, with thresholds sorted smallest first. At ₹18 lakh, new-regime tax is ₹1.6 lakh before cess.
  • SUMIFS and pivot tables summarise data.
  • Tools fail silently, as the lost COVID test results of 2020 showed. Check row counts, totals, spaces, duplicates and hidden errors.

Go deeper

Complete this lesson
Pass the quiz below (60% or more) to earn +50 XP and unlock the next lesson.
Quiz not passed yet
🧠

Quiz: Tables, lookups and pivots: shaping real financial data

5 questions · pass 60% to complete