Extract unique items from a list

I'm trying to create a unique list based on an existing list containing duplicates on numbers. Newest version.


Example:


DateBought
...

Banana

...Apple
...Apple
...Mango
...Banana
...
...


Unique Items
Banana
Apple
Mango


I want the list to be dynamic. Excel does what I want with the formula:


IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"")


Whereas $B$2:$B$9 is the Bought list and $D$1:D1 is an expanding domain in the Unique Items list. Numbers seems to struggle with arrays (demanding unique values.) This is not the first time I run into this problem (Here, it is the COUNTIF function). Is there a solution to this (other than switching to Excel)?


Thanks


Triklops

Posted on Jul 28, 2018 3:42 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 29, 2018 6:29 PM

Hi Triklops,


Here's the same thing, done in Numbers.

User uploaded file

The process relies on an added index column, which indexes, with a serial number, the first appearance of each item in the list.

There are two formulas involved, one in the index column, Column C of Table 1 (on the left), the other in Column A of the single column Table 2 (on the right).

Here are the tables again, with column C unhidden, and the formula in C2 shown in the Formula Editor below the tables.

User uploaded file

There are five distinct items in the list, including the two, Mango and Kumquat, which are unique within the context of the table.


C2: IF(COUNTIF(B$2:B2,B2)=1,MAX(C$1:C1)+1,"")

The formula shown is entered in C2, and filled down to the end of column C.

COUNTIF counts the occurrences, from row 2 to 'this row' of the item in 'this row' of column B.

If the count is 1, IF calls MAX, MAX returns the MAXimum value in the cells in column C that are above 'this row', +1 adds one to that value, and the result is returned to 'this cell' by IF. If the count is not 1, IF skips the call to MAX, and returns a null string ( "" ), which makes 'this cell' appear 'blank'.



Table 2 contains this formula, entered in A2 and filled to the end of column A:


A2: IF(ROW()−1>MAX(Table 1::C),"",INDEX(Table 1::B,MATCH(ROW()−1,Table 1::C,0)))


The part in normal type, including the final parenthesis, is a switch that prevents calculation after the last item has been listed. The core part of the formula is shown in bold.


ROW()-1 returns a number one less than the number of 'this row' and hand it to MATCH as its search-for value.

MATCH searches for this value in column C of Table 1, and returns a number indicating the position of this value in the list in column 1. The value is handed to INDEX, where it serves as the row-index.

INDEX looks in column B of Table 1, and returns the value from the row indicated by MATCH.


"I want the list to be dynamic."


For a dynamic list, you will need to use formulas, such as the ones presented here. Your only manual intervention will be to add rows to Table 2 to ensure that there are enough to contain all of the distinct values to be listed.


If you can accept a requirement for manual intervention each time you need the list updated, it is also possible to extract the distinct values using an AppleScript (or an Automator Service containing an AppleScript). SGIII has written an Automator Service for this purpose. It does the job quickly and simply, but does not update automatically.

SG will likely be along within a day of your posting with a more detailed description.


Regards,

Barry

2 replies
Question marked as Top-ranking reply

Jul 29, 2018 6:29 PM in response to Triklops

Hi Triklops,


Here's the same thing, done in Numbers.

User uploaded file

The process relies on an added index column, which indexes, with a serial number, the first appearance of each item in the list.

There are two formulas involved, one in the index column, Column C of Table 1 (on the left), the other in Column A of the single column Table 2 (on the right).

Here are the tables again, with column C unhidden, and the formula in C2 shown in the Formula Editor below the tables.

User uploaded file

There are five distinct items in the list, including the two, Mango and Kumquat, which are unique within the context of the table.


C2: IF(COUNTIF(B$2:B2,B2)=1,MAX(C$1:C1)+1,"")

The formula shown is entered in C2, and filled down to the end of column C.

COUNTIF counts the occurrences, from row 2 to 'this row' of the item in 'this row' of column B.

If the count is 1, IF calls MAX, MAX returns the MAXimum value in the cells in column C that are above 'this row', +1 adds one to that value, and the result is returned to 'this cell' by IF. If the count is not 1, IF skips the call to MAX, and returns a null string ( "" ), which makes 'this cell' appear 'blank'.



Table 2 contains this formula, entered in A2 and filled to the end of column A:


A2: IF(ROW()−1>MAX(Table 1::C),"",INDEX(Table 1::B,MATCH(ROW()−1,Table 1::C,0)))


The part in normal type, including the final parenthesis, is a switch that prevents calculation after the last item has been listed. The core part of the formula is shown in bold.


ROW()-1 returns a number one less than the number of 'this row' and hand it to MATCH as its search-for value.

MATCH searches for this value in column C of Table 1, and returns a number indicating the position of this value in the list in column 1. The value is handed to INDEX, where it serves as the row-index.

INDEX looks in column B of Table 1, and returns the value from the row indicated by MATCH.


"I want the list to be dynamic."


For a dynamic list, you will need to use formulas, such as the ones presented here. Your only manual intervention will be to add rows to Table 2 to ensure that there are enough to contain all of the distinct values to be listed.


If you can accept a requirement for manual intervention each time you need the list updated, it is also possible to extract the distinct values using an AppleScript (or an Automator Service containing an AppleScript). SGIII has written an Automator Service for this purpose. It does the job quickly and simply, but does not update automatically.

SG will likely be along within a day of your posting with a more detailed description.


Regards,

Barry

Jul 29, 2018 2:18 PM in response to Triklops

The Copy Distinct Automator Service (Dropbox download) approach is similar to Excel's Data > Table Tools > Remove Duplicates.


To install double-click the downloaded .workflow package and if necessary give permission at System Preferences > Security & Privacy. Also make sure Automator.app is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.


To us select the cells containing possible duplicates (in the example B2:B6) and choose Copy Distinct from the Numbers > Services menu. Then click once in a cell where you want the results (A2 of your second table) and type command-v or choose Edit > Paste and Match Style from the menu.


This isn't fully automated but it takes only a few seconds to update.


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.

Extract unique items from a list

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