ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Projects
  3. How to Build a Stock Portfolio Tracker in Excel

How to Build a Stock Portfolio Tracker in Excel

By ExcelReady Team·Updated November 3, 2026·7 min read

The short answer

A stock portfolio tracker in Excel is a table with one row per holding: shares, cost per share and current price. Shares times cost gives the cost basis, shares times price the market value, and the difference is the gain. Gain divided by cost is the percent return. SUMIF totals each sector and XLOOKUP pulls prices from a list.

Key takeaways

  • Keep one row per holding with shares, cost per share and price; every other column is a formula.
  • Percent return is gain divided by cost basis, =(G2-F2)/F2, formatted as a percentage.
  • SUMIF totals market value by sector, and dividing by the grand total gives each sector's share.
  • Keep prices in their own list and fetch them with XLOOKUP, so updating prices never touches your formulas.
  • A tracker records and summarises what you own; it is not a source of advice on what to buy or sell.
On this page+
  1. What columns does a portfolio tracker need?
  2. Step 1: Enter your holdings
  3. Step 2: Calculate cost basis, value and gain
  4. Step 3: Calculate the percent return
  5. Step 4: Total by sector with SUMIF
  6. Step 5: Average cost from a purchase log
  7. Step 6: Pull prices from a price list with XLOOKUP
  8. Going further: dividends and yearly returns
  9. Practise it

A stock portfolio tracker in Excel is one table: a row for each holding, with the shares you own, what you paid and today's price. A few simple formulas turn that into cost basis, market value, gain and percent return, and SUMIF and XLOOKUP add sector totals and a price list. This guide builds the whole tracker step by step, and it is also a good practice project for the formulas job tests ask about.

The stocks below are placeholders (Stock A to Stock F) and every figure is an example, checked in Python. Nothing here is investment advice or a real price.

What columns does a portfolio tracker need?#

A tracker needs three inputs per holding and four formula columns. You type the inputs; Excel works out the rest.

ColumnTypeWhat it holds
A StockInputName or ticker
B SectorInputTech, Health, Energy…
C SharesInputHow many you own
D Cost/shareInputAverage price you paid
E PriceInput or lookupLatest price
F Cost basisFormula=C2*D2
G ValueFormula=C2*E2
H GainFormula=G2-F2
I Return %Formula=H2/F2

Format the data as an Excel table (Windows: Ctrl+T; Mac: ⌘T). New rows then pick up the formulas automatically.

Step 1: Enter your holdings#

Type one row per stock. Here is the example portfolio used throughout:

StockSectorSharesCost/sharePrice
Stock ATech205062
Stock BTech10120108
Stock CHealth154046
Stock DEnergy302527.50
Stock EHealth89099
Stock FEnergy126054

If you bought the same stock more than once, use the average cost per share. Step 5 shows how to work that out from a purchase log.

Step 2: Calculate cost basis, value and gain#

Cost basis is what you paid in total; market value is what the shares are worth at the current price. In row 2:

Excel formula
F2: =C2*D2
G2: =C2*E2
H2: =G2-F2

For Stock A, that gives a cost basis of 1,000, a value of 1,240 and a gain of 240. Fill the formulas down to row 7 (Windows: Ctrl+D; Mac: ⌘D). Stock B shows a gain of -120: a negative gain is a loss.

Step 3: Calculate the percent return#

Percent return is the gain divided by the cost basis. In I2:

Excel formula
=H2/F2

Format the column as a percentage (Windows: Ctrl+Shift+%; Mac: Control+Shift+%). Stock A returns 24%, Stock C 15% and Stock B -10%. This is the classic percent change formula, (new − old) / old, explained in full in the guide to the percent change formula. Always divide by the cost basis, the starting value, not by today's value.

Add a total row underneath. Total cost is 4,990, total value 5,275 and total gain 285. For the portfolio's return, divide the total gain by the total cost: =H8/F8 gives about 5.71%. Don't average the percent column instead. That treats a small holding the same as a large one.

Step 4: Total by sector with SUMIF#

SUMIF adds the values in one column where another column matches a condition. To total the Tech holdings:

Excel formula
=SUMIF($B$2:$B$7,"Tech",$G$2:$G$7)

The result is 2,320 (Stock A's 1,240 plus Stock B's 1,080). Put the sector names in a small summary table and point the criteria at those cells instead of typing "Tech". Then divide by the total value for each sector's share of the portfolio:

SectorValueShare
Tech2,32043.98%
Health1,48228.09%
Energy1,47327.92%

The share formula is =SUMIF($B$2:$B$7,K2,$G$2:$G$7)/$G$8, with the sector name in K2 and the total value in G8. The $ signs keep the ranges fixed as you fill down. See how SUMIF works and how to calculate a percentage of a total for more examples, or check the SUMIF function guide for the syntax.

Step 5: Average cost from a purchase log#

If you buy the same stock several times, keep a purchase log and let SUMIF work out the average cost. A log has one row per purchase:

DateStockSharesTotal paid
2025-02-10Stock A10450
2025-08-04Stock A10550
2025-03-17Stock C15600

The average cost of Stock A is the total paid divided by the total shares:

Excel formula
=SUMIF(Log!B:B,"Stock A",Log!D:D)/SUMIF(Log!B:B,"Stock A",Log!C:C)

That is 1,000 / 20 = 50 per share, the figure used in the holdings table. The shares column in the holdings table can use the same idea: =SUMIF(Log!B:B,A2,Log!C:C). Sales can go in the same log as negative shares.

Step 6: Pull prices from a price list with XLOOKUP#

Keep prices on their own sheet and look them up, so updating prices never means editing formulas. Put a Prices sheet with stock names in column A and prices in column B. Then in E2 of the holdings table:

Excel formula
=XLOOKUP(A2,Prices!A:A,Prices!B:B,"Not found")

XLOOKUP finds the stock name in the price list and returns its price. The fourth argument shows "Not found" instead of #N/A when a name is missing or misspelled. XLOOKUP needs Excel 2021 or Microsoft 365; in older versions use =VLOOKUP(A2,Prices!A:B,2,FALSE). The guide to XLOOKUP and the XLOOKUP function guide cover the details.

Where do the prices come from? You can paste them in from a statement. In Microsoft 365, the Stocks data type (Data > Stocks) can also fill in prices for many listed companies, and the STOCKHISTORY function returns past prices. Both depend on your Excel version and region, and quotes can be delayed, so note the date you updated them.

Going further: dividends and yearly returns#

A few extra columns make the tracker more useful:

  • Dividends. Log each dividend with the stock and amount, and total it with =SUMIF(Div!B:B,A2,Div!C:C). Add it to the gain for a total return.
  • Annual return. A 20% gain over four years is not 5% a year. Use the CAGR formula to turn a multi-year return into a yearly rate.
  • Biggest movers. Sort by the Return % column, or use conditional formatting to colour gains green and losses red.

Practise it#

This tracker uses three core skills: totals with conditions, percent change and lookups. Practise SUMIF in a live spreadsheet, then practise percentages and percent change and practise XLOOKUP. Each lesson checks your formula as soon as you type it. Then try the exercise on this page to work out the Tech share of the example portfolio.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

What share of this example portfolio is in Tech? In G2, total the Tech values with SUMIF and divide by the total of E2:E7: =SUMIF(B2:B7,"Tech",E2:E7)/SUM(E2:E7).

fx
ABCDEFGH
1
Stock
Sector
Shares
Price
Value
2
Stock A
Tech
20
62
1240
Tech share
3
Stock B
Tech
10
108
1080
4
Stock C
Health
15
46
690
5
Stock D
Energy
30
27.5
825
6
Stock E
Health
8
99
792
7
Stock F
Energy
12
54
648
8
9
10

Tip: SUMIF(B2:B7,"Tech",E2:E7) adds the Tech values (2,320). Divide by SUM(E2:E7), the whole portfolio (5,275). The answer is about 0.4398, or 43.98%.

Practise this in a lesson

LessonSUMIFAdd up only the numbers that meet a condition, with and without a separate sum range.LessonPercentages and % changeCalculate percent change with (new - old) / old, format it as a percentage, and grow a number by a percent.LessonXLOOKUPLook up in any direction with XLOOKUP and show a friendly message when nothing matches.Function guideSUMIFAdd up values that meet one condition with SUMIF. Totals by category, person or amount, the argument-order trap, and a live exercise.Function guideXLOOKUPXLOOKUP explained with real examples: exact matches, looking left and custom not-found messages, plus a live exercise to try now.

Frequently asked questions

How do I track my stock portfolio in Excel?

+

Make a table with one row per holding and columns for shares, cost per share and current price. Add formula columns for cost basis, market value, gain and percent return, then total them at the bottom.

How do I calculate percent gain on a stock in Excel?

+

Subtract the cost basis from the market value and divide by the cost basis, for example =(G2-F2)/F2. Format the cell as a percentage. A negative result is a loss.

Can Excel get stock prices automatically?

+

In Microsoft 365, the Stocks data type on the Data tab can fill in prices for many listed companies, and STOCKHISTORY returns past prices. Availability depends on your version and region, and quotes can be delayed.

How do I calculate the average cost of shares bought at different prices?

+

Divide the total amount paid by the total shares bought. With a purchase log, that is SUMIF of the cost column divided by SUMIF of the shares column for the same stock.

How do I show what percent of my portfolio is in each sector?

+

Use SUMIF to total the market value for one sector, then divide by the total market value of the portfolio. Format the result as a percentage.

Sources

  • SUMIF function - Microsoft Support
  • XLOOKUP function - Microsoft Support
  • Calculate percentages - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What columns does a portfolio tracker need?
  2. Step 1: Enter your holdings
  3. Step 2: Calculate cost basis, value and gain
  4. Step 3: Calculate the percent return
  5. Step 4: Total by sector with SUMIF
  6. Step 5: Average cost from a purchase log
  7. Step 6: Pull prices from a price list with XLOOKUP
  8. Going further: dividends and yearly returns
  9. Practise it

Keep reading

Math· 6 min read

Percent Change Formula in Excel (With Examples)

The percent change formula in Excel is =(new-old)/old. If last year's sales are in B2 and this year's in C2, type =(C2-B2)/B2, then press Ctrl+Shift+% to show it as a percentage. A positive result is an increase and a negative result is a decrease. Always divide by the old value.

Math· 6 min read

CAGR Formula in Excel: Compound Annual Growth Rate

To calculate CAGR in Excel, divide the ending value by the starting value, raise the result to the power of one over the number of years, and subtract 1: =(B6/B2)^(1/4)-1. Growth from 50,000 to 80,000 over four years gives 12.47%. The number of years is the number of periods between the values, not the number of rows.

Math· 6 min read

How to Calculate Percentage of Total in Excel

To calculate the percentage of total in Excel, divide each value by the total and lock the total with dollar signs: =B2/$B$6, or =B2/SUM($B$2:$B$5) without a total row. Fill the formula down and press Ctrl+Shift+% (Control+Shift+% on a Mac) to show percentages. The results should add up to 100%.

More on projects

  • Build a Subscription Tracker in Excel
  • How to Analyse Survey Results in Excel
  • Build a Task Tracker in Excel With Status and Due Dates
  • Make a Simple Timesheet in Excel With Formulas
  • Build an Employee Training Tracker in Excel
  • How to Prepare a Trial Balance in Excel With SUMIFS
All projects articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free