How to create categories with counts and sub categories in Numbers app?

In order to make this not too complicated I am going to break the questions separately, as we progress through the thread. In the sample attached I want

  1. a count of the number of people in each group, 21, 22,30,31, etc. I think I've got that
  2. Then a total count of each decade group, under 20, under 30, etc. This is the first question.
  3. Then I want to graph them. Like in a bar chart and want the count number to display for each bar/category. When we get question 2 resolved then we can move on to the graphing.

Attached is for the first question. I think I have that.

Then I want one row per decade with the total for that decade. Is it possible to do it programmatically? I can think of a way by adding a row after each decade and creating the COUNT function, but that is a manual process.


[Edited by Moderator]

Original Title: How to create categories with counts and sub categories

MacBook Air 15″, macOS 15.5

Posted on Jul 18, 2025 6:35 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 19, 2025 11:40 AM

You can use the FREQUENCY function instead of LET to make a histogram of the data. The ages in column A need to be integer values (truncated to the integer year) for the following formula to give correct results:


Table 2::B2 =INDEX(FREQUENCY(Table 1::A,{19,29,39,49}),ROW()−1)

Fill down to the other rows

The age buckets/bins will be <20 (up to age 19), 20-29, 30-39, 40-49, and 50+

In later versions you don't need INDEX and the FREQUENCY function spills down into the other rows on its own.


They need to be integer years because, for example, an age such as 29.1 is >29 and will get binned into the next bin, the one meant for 30-39.



8 replies
Question marked as Top-ranking reply

Jul 19, 2025 11:40 AM in response to rjmman1

You can use the FREQUENCY function instead of LET to make a histogram of the data. The ages in column A need to be integer values (truncated to the integer year) for the following formula to give correct results:


Table 2::B2 =INDEX(FREQUENCY(Table 1::A,{19,29,39,49}),ROW()−1)

Fill down to the other rows

The age buckets/bins will be <20 (up to age 19), 20-29, 30-39, 40-49, and 50+

In later versions you don't need INDEX and the FREQUENCY function spills down into the other rows on its own.


They need to be integer years because, for example, an age such as 29.1 is >29 and will get binned into the next bin, the one meant for 30-39.



Jul 19, 2025 9:30 PM in response to rjmman1

If you are running macOS 15.5 (as in your profile) then just go to the Mac App Store and update Numbers. You will then have the dynamic array "spill" functions including LET, MAP, LAMBDA, etc., etc.


If you do that, FREQUENCY will also spill so you don't have to wrap it in INDEX.


In the latest version and in many older versions of Numbers, you can also use the Pivot Table approach, which is easier than Categories:


Add the Decade helper column, populated with something like this formula in D2, filled down:


=IFS(A2<=30,"21-30",A2<=40,"31-40",A2<=50,"41-50",TRUE,"Over 50")


Click in the table, then in the menu choose Organize > Create Pivot Table > On Current Sheet. In the Pivot Options pane at the right drag the fields down into Rows and Values boxes below as shown in the screenshot.




Select all the cells in the Pivot Table and Insert > Chart > 2D Column.


Done!


The one (small) drawback of a Pivot Table. If things change, e.g. you later change or add data to Table 1, then you need to "refresh," easily done. Click the Pivot Table and choose Organize > Refresh Pivot Table.


When you do that, the Pivot Table and the chart based on it are updated.


More on Pivot Tables in the User Guide:


Intro to pivot tables in Numbers on Mac - Apple Support


SG








Jul 19, 2025 2:27 AM in response to rjmman1

Quite a few approaches to this in Numbers (and Excel).


Approach 1 - Old school. Add a helper column with decade labels and use SUMIF in a separate table where you have entered the distinct decade labels manually. Base a chart on that second table. Make sure Column A is defined as a Header Column.



Approach 2 - Leverage the Categories functionality. Add helper column as in approach 1, and categorize on that column. Then Collapse Peer Groups.




Select visible cells, and Edit > Paste and Match Style into a separate existing table that you have already set up. Clean up that table manually and use it as the basis of the chart. (To chart select the cells in the table and Insert > Chart. See built-in 'Charting Basics' template for examples.)


Approach 3 - Use the new dynamic array "spill" functions to populate a table that you can chart. No helper column needed. Compact and powerful, but a learning curve.





In A2: LET(
ages, Table 1::A,
decade_labels, MAP(ages, LAMBDA(age,
 IFS(age≤30, "21-30",
 age≤40, "31–40",
 age≤50, "41–50",
TRUE, "Over 50")
 )),
 SORT(UNIQUE(decade_labels,unique-by,occurrence),sort-index,sort-order,sort-by)
)


In B2: LET(
 ages, Table 1::A,
 decades,A2#,
decade_labels, MAP(ages, LAMBDA(age,
IFS(age≤30, "21-30",
 age≤40, "31–40",
 age≤50, "41–50",
 TRUE, "Over 50")
 )),
MAP(decades, LAMBDA(decade, COUNTIF(decade_labels, decade)))
)


In your menu go to Help > Formulas and Functions Help for more on any of these functions. Also good descriptions of Categories in Help > Numbers Help.


You could also use a Pivot Table and copy results out into a table for charting (similar to Approach 2.)


SG









This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to create categories with counts and sub categories in Numbers app?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.