How to Count Individual Digits in Four-Digit Excel Numbers
Question details
The user wants to count the frequency of each digit (0 through 9) across a range of four-digit values, preserving leading zeros.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Analyzing numerical data to find the occurrence frequency of individual digits within four-digit strings.
- Observed behavior
- The goal is to split the four-digit numbers into individual digits and automatically output a summary table of their counts.
Ensure your numbers are formatted as Text if they contain leading zeros (e.g., '0123') so that the spreadsheet software doesn't automatically remove them. Also, verify that your software version supports dynamic array functions like LET, LAMBDA, and TOCOL.
Use the LET and REDUCE Functions to Count Digits
This method splits each four-digit number into an array of individual digits and creates a summary count table.
This formula leverages Excel's dynamic array capabilities to isolate each character in your cells, stack them into a single column, and compute the totals for each unique digit.
Click on the cell where you want the top-left corner of the summary table to appear.
Type the following formula, replacing 'numbers' with your actual data range: =LET(explode,LAMBDA(integer,MID(integer,{1,2,3,4},1)),number_vector,TOCOL(explode(numbers)),unique_numbers,SORT(UNIQUE(number_vector)),CountNumbers,LAMBDA(acc,i,LET(total,SUM(N(i=number_vector)),VSTACK(acc,HSTACK(i,total)))),REDUCE({"Totals","Count"},unique_numbers,CountNumbers))
Press Enter. The formula will automatically spill the results into adjacent cells, displaying the unique digits alongside their respective counts.

Use the GROUPBY Function for a Shorter Formula
If you are using a newer version of Excel that supports the GROUPBY function, you can achieve the same result with a more concise formula.
Easily Manage Array Formulas with WPS Spreadsheet
WPS Spreadsheet fully supports advanced array functions and text manipulations, making complex data analysis tasks like digit extraction simple and efficient.
- 1. Open WPS Spreadsheet: Launch WPS Office and create a new Spreadsheet document or open your existing file.
- 2. Format Data as Text: Select the column containing your four-digit values, right-click, choose 'Format Cells', and set it to 'Text' to preserve leading zeros.
- 3. Apply the Formula: Use the provided LET and LAMBDA formulas in an empty cell to automatically calculate your digit frequencies.

Frequently Asked Questions
Why are my leading zeros disappearing when I enter four-digit numbers?
By default, spreadsheet software treats numerical entries as integers and removes leading zeros. To prevent this, format the cells as 'Text' before entering the data, or type an apostrophe (') before the number.
Can I adapt this formula for numbers with more or fewer digits?
Yes. In the formula, locate the array {1,2,3,4} inside the MID function. If your numbers have 5 digits, change it to {1,2,3,4,5}. You can adjust this array based on the length of your text strings.
What does the TOCOL function do in this formula?
The TOCOL function takes the 2D array generated by splitting the digits and stacks them into a single, continuous column (a vector). This makes counting the occurrences of each digit much easier.
Why is the formula returning a #NAME? error?
This error usually means your version of the spreadsheet software does not support one or more of the dynamic array functions used, such as LET, LAMBDA, or TOCOL. Ensure your software is updated to a version that supports modern array formulas.




