Function Problems

How to Find Max, Min, and Median Values with STOCKHISTORY in Excel

Anum MushtaqAnum Mushtaq Nov 4, 2026 869 views

Question details

The user wants to calculate the maximum, minimum, median, and Nth values (and their corresponding dates) directly from the STOCKHISTORY function using a single algorithmic dynamic-array formula.

How to Extract Max, Min, Median, and Nth Values Using STOCKHISTORY in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
Analyzing historical stock market data logically within a single formula cell without generating external helper columns.
Observed behavior
The user needs an all-in-one algorithmic formula to process the arrays generated by STOCKHISTORY, but struggles to correctly retrieve specific dates tied to median or Nth values due to data ties and even-number median averages.
Before you start

Ensure you are using Microsoft 365, as the STOCKHISTORY function is a connected data type not available in older standalone versions of Excel. Familiarize yourself with the LET function, which is required to efficiently store and manipulate array variables in memory.

Solution 1Recommended

Use the LET Function to Extract Max and Min Dates

Use the LET function to store the STOCKHISTORY array in memory, separate the dates and closing prices, and calculate MAX or MIN with their associated dates.

By combining the LET function with STOCKHISTORY, you eliminate the need for helper columns on your worksheet. You can separate the dates and closing prices into defined variables, then use FILTER or XLOOKUP to return the exact date when the highest or lowest price occurred.

1
Define the LET Formula Structure

Select an empty cell and type the beginning of the LET function to define your stock data. For example: =LET(data, STOCKHISTORY("MSFT", "1/1/2023", "12/31/2023"), dates, CHOOSECOLS(data, 1), prices, CHOOSECOLS(data, 2),

2
Add the Calculation for Maximum Value

To find the date of the highest price, complete the LET function using XLOOKUP. Add the following as the calculation argument: XLOOKUP(MAX(prices), prices, dates))

3
Execute the Dynamic Array

Press Enter to execute the formula. Excel will store the STOCKHISTORY matrix entirely in memory and output only the date associated with the maximum or minimum closing price.

Use the LET Function to Extract Max and Min Dates
Performance Benefit: Formulas using LET process calculations much faster since the STOCKHISTORY data service only needs to be queried once.
Free Microsoft Office alternative

Try WPS Office for Powerful Data Analysis and Spreadsheets

While the STOCKHISTORY function requires an expensive Microsoft 365 subscription, WPS Office provides an incredibly robust, free spreadsheet tool that supports advanced dynamic arrays, the LET function, and comprehensive financial data analysis.

  1. 1. Download WPS Office: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the Software: Run the downloaded installer file and follow the simple on-screen instructions to set up WPS Office on your computer.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to seamlessly continue your data analysis.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv)Supports advanced dynamic arrays, LET, XLOOKUP, and standard financial functionsFree, lightweight, and installs quickly without eating up system resourcesFamiliar user interface makes switching from Excel completely seamless
microsoft office alternative - wps office

Frequently Asked Questions

Why can't Excel find a date for my MEDIAN STOCKHISTORY value?

If your STOCKHISTORY dataset has an even number of entries, the median is calculated mathematically by averaging the two middle values. Since this new averaged result does not necessarily correspond to an actual historical trading date, a single definitive date cannot be returned without defining specific rounding logic.

Can I use STOCKHISTORY without a Microsoft 365 subscription?

No, the STOCKHISTORY function relies on proprietary connected financial data services that are exclusive to Microsoft 365. Older standalone versions of Excel do not support this function natively.

How do I calculate the Nth earliest date using STOCKHISTORY?

You can use the SMALL function combined with the INDEX function to target the Nth smallest date directly from the date column array returned by the initial STOCKHISTORY call.

Why does my antivirus block spreadsheet templates containing STOCKHISTORY?

Strict antivirus software sometimes flags spreadsheets containing complex dynamic arrays or automated external web data connections as false positives. To avoid this, manually build the formula directly in a blank workbook rather than downloading external macro-enabled templates.