Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Find the max value per category

From a table that records date, category and value, I wish to create a summary table that contains:


    1. the highest value for each category, and
    2. the date this occurred.


For example:



A careful search shows that a similar question was asked in 2011, and wish to know if a better solution is now possible with the latest version of Numbers: https://discussions.apple.com/thread/3354084


I'd settle for missing out on the "date achieved" column if a good solution can otherwise be found for the "highest per category".


Thank you.

Mike

Posted on Jul 23, 2019 7:30 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 24, 2019 12:49 AM

Here's an alternate method, using formulas to separate the Lift values into separate columns by category, then to extract the maximum value from each of those columns to a Summary table, and finally, to use the extracted value as a search value to locate the earliest appearance of that value in the category column specific to the category in column A of the Summary table, and retrieve the date from the same row of column A of the Data table.


The Data table contains four added columns, one for each category being tracked. In use, these columns, D to G, would be hidden.

The formula is entered as shown in D2 of this table, then filled down to the end of column D, and right to column G. The formula copies the values in column C of the table into the appropriate category column, as seen in the table, and places a null string ( "" ) in 'this row' of the other three category columns.


On the summary table, the four categories are listed in column A. The table contains two formulas, one in column B, the other in column C.

The first formula, MAX(Table 1::D) returns the maximum value in column D of Table 1, the main table.

The formula is filled down column B to row 5, then each copy except the original is edited, replacing "Table 1::D" with a reference to the column containing values for the lift type listed on 'this row' of column A.


The second formula: INDEX(Table 1::A,MATCH(MAX(Table 1::D),Table 1::D,-))

is entered in C2, then filled down to C5.

On each roe, the two references to Table 1::D are edited to reference the column containing the values for the lift type on 'this row' of column A.

Match searches for the Maximum value in its assigned column, and returns a number corresponding to that values position in the list in that column.

That number is passed to INDEX, which returns the value in that position of column A of Table 1—the date on which that maximum was achieved.


MATCH can be set to accept

  • the largest value that is less than or equal to the search value,
  • only an exact match to the search value, or
  • the smallest value that is more than or equal to the search value.


Any of the three will find the exact value in this case. But the three do not all search in the same direction. Largest and exact start at the bottom of the table and work their way up, stopping at the first exact match, if there is one; smallest starts at the top of the table, works its way down, and stops at the first exact match, if there is one.


In Row 8 of Table 1, I've changed the Press data from your original value, 65, to 78 to make two lines in the table have the same maximum value for this lift. With MATCH set to smallest, and searching top to bottom, the first instance of that max it finds in the one on row 8 of the table, so Index gets the date value from row 8 (Jan 7). With MATCH set to largest or exact, the first instance would be the one in row 12, and INDEX would return the date in that row, Jun 11.


In use, with columns D through G of Table 1 hidden, the setup would look like this:

Regards,

Barry


19 replies
Sort By: 
Question marked as Top-ranking reply

Jul 24, 2019 12:49 AM in response to itsapplemike

Here's an alternate method, using formulas to separate the Lift values into separate columns by category, then to extract the maximum value from each of those columns to a Summary table, and finally, to use the extracted value as a search value to locate the earliest appearance of that value in the category column specific to the category in column A of the Summary table, and retrieve the date from the same row of column A of the Data table.


The Data table contains four added columns, one for each category being tracked. In use, these columns, D to G, would be hidden.

The formula is entered as shown in D2 of this table, then filled down to the end of column D, and right to column G. The formula copies the values in column C of the table into the appropriate category column, as seen in the table, and places a null string ( "" ) in 'this row' of the other three category columns.


On the summary table, the four categories are listed in column A. The table contains two formulas, one in column B, the other in column C.

The first formula, MAX(Table 1::D) returns the maximum value in column D of Table 1, the main table.

The formula is filled down column B to row 5, then each copy except the original is edited, replacing "Table 1::D" with a reference to the column containing values for the lift type listed on 'this row' of column A.


The second formula: INDEX(Table 1::A,MATCH(MAX(Table 1::D),Table 1::D,-))

is entered in C2, then filled down to C5.

On each roe, the two references to Table 1::D are edited to reference the column containing the values for the lift type on 'this row' of column A.

Match searches for the Maximum value in its assigned column, and returns a number corresponding to that values position in the list in that column.

That number is passed to INDEX, which returns the value in that position of column A of Table 1—the date on which that maximum was achieved.


MATCH can be set to accept

  • the largest value that is less than or equal to the search value,
  • only an exact match to the search value, or
  • the smallest value that is more than or equal to the search value.


Any of the three will find the exact value in this case. But the three do not all search in the same direction. Largest and exact start at the bottom of the table and work their way up, stopping at the first exact match, if there is one; smallest starts at the top of the table, works its way down, and stops at the first exact match, if there is one.


In Row 8 of Table 1, I've changed the Press data from your original value, 65, to 78 to make two lines in the table have the same maximum value for this lift. With MATCH set to smallest, and searching top to bottom, the first instance of that max it finds in the one on row 8 of the table, so Index gets the date value from row 8 (Jan 7). With MATCH set to largest or exact, the first instance would be the one in row 12, and INDEX would return the date in that row, Jun 11.


In use, with columns D through G of Table 1 hidden, the setup would look like this:

Regards,

Barry


Reply

Jul 26, 2019 11:55 AM in response to SGIII

Hi SG,


Nice use of COUNTIFS to answer two questions:

  1. Are there numbers larger than 'this' one in this category?
  2. Has this number already been listed for this category?


And a nice use of SUMIF to return the single number for each category from column C

(AND the "SUM" of the Date and time value on that row!).


Great to see some 'out of the box lateral thinking going on!


Regards,

Barry

Reply

Jul 26, 2019 4:51 AM in response to itsapplemike

Hi Mike,


This may help you and other users of Smart Categories in Numbers 6.1


After adding Smart Categories and Maximum to the Log table (following SG's advice) add another column "Code" (column D). That will help us to match the Date to the maximum weight in each Lift category.



=B2&C2 (and fill down). Fill down will fill the formula into only the body rows.


Here is your "Best" table. The values in Column A (Lift) are typed in.


Formula in B2 =Log::$C $Squat (Maximum) and edit for each row in Column B


Moving to Column D (Code)



Now we have something with which to compare between the two tables and find the appropriate Date.



All done by pointing and clicking.


Regards,

Ian.


Reply

Jul 26, 2019 5:56 AM in response to SGIII

Hi SG,


Oh! All those nasty extra columns!

We can hide those extra columns (Column D on both tables) for a neater display. The formulas continue to work:



But I like to use extra columns because they allow my brain to break the problem into small steps. Then we hide those intermediate ("engine room") columns.


Captain Kirk on the bridge: "Kirk to Engine Room. Warp 4, Mr Scott."

Scotty in the Engine Room: "Aye aye Captain. Just adding a few more columns..."


Regards,

Ian.

Reply

Jul 26, 2019 7:10 AM in response to itsapplemike

If you want a separate table here's a more compact solution (one extra column, three formulas):




The formula in D1 of the 'Log' table, filled down:


=IF(AND(COUNTIFS(B,B,C,">"&C)=0,COUNTIFS(OFFSET(D$1,0,0,ROW()−1),C,OFFSET(B$1,0, 0,ROW()−1),B)=0),C,"")


The formula in B2 of the 'Best' table, filled down:

=SUMIF(Log::B,A2,Log::D)


The formula in C2 of the 'Best' table, filled down:


=SUMIFS(Log::A,Log::B,A2,Log::D,B2)


SG


Reply

Jul 23, 2019 11:19 PM in response to itsapplemike

Hi Mike,


What version of Numbers are you using? (Numbers menu > About Numbers)

What version of OS X / macOS is installed on your Mac (Apple menu > About this Mac)


Categories, as noted in the discussion you linked to, was a feature introduced in Numbers '09 (Numbers 2.n).

When Numbers (and Pages) were reconstructed and completely rewritten, the post-'09 versions were missing several features available in the '09 versions.


Categories, renamed Smart Categories, was included in Numbers 6 (the current version) after an absence of several years.


Using Smart Categories is likely the quickest way to view the maximum value in each category used in your table, and, since it groups (and sorts?) and displays the complete rows of the table, the rows containing those maxima will also display the dates on which each maximum was achieved.


Regards,

Barry

Reply

Jul 24, 2019 10:16 AM in response to Yellowbox

And, going by the sorted results (in the Squat category of Ian's example), duplicate values will stay in the same date order, putting the earlier one to the top of the list in cases where the maximum has been reached more than once.


Regards,

Barry

Reply

Jul 26, 2019 5:09 PM in response to Barry

Barry wrote:

Great to see some 'out of the box lateral thinking going on!


Hi Barry,


Thanks! I can only take partial credit. I remember some of that lateral thinking was expressed years ago, by I think Badunit. Rebuilding the logic wasn't easy, but I must say it has stood the test of time!


SG

Reply

Find the max value per category

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