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

How do i create a subset of data in numbers 3.5

Hi


I use Numbers 3.5.2 on my MacBook Pro. I am familiar with Excel but finding it difficult to transfer my Pivot Table knowledge into Numbers. I just about understand how SUMIF works now but have a further question related to summarising data from one table into another table and would very much appreciate some guidance as I can't find any tutorials covering this subject.


Example


Assume Table 1 has a column of data called Surname and another called Pay.

Table 1 has 100 rows and there are 20 unique entries for Surname.


I want to summarise the Table 1 data into Table 2 by Name by Pay.

But I don't want to manually input all the unique entries of Surname into Table 2.

I want to create a column called Surname in Table 2 that holds 1 row for each unique Surname in Table 1.

So Table 2 would have 20 rows.

I will then use SUMIF to total all Pay for each Surname now in Table 2 by referencing Pay from Table 1.

It would be great if rows in Table 2 were created automatically when entering a row in Table 1 (assuming it's the first row in Table 1 with that specific Surname) but that's not absolutely essential if it's complex.


I do have a further question relating to this but any help to get me to understand how to effectively extract the 20 entries of Surname from Table 1 into Table 2 would be tremendous. In anticipation, thank you for reading.


Regards

Martin

MacBook Pro, OS X Yosemite (10.10.2), Numbers 3.5.2

Posted on Mar 2, 2015 8:29 AM

Reply
Question marked as Best reply

Posted on Mar 2, 2015 9:09 AM

SGIII made a handy script to copy the unique items:

And for things like this you may find this Copy Distinct Automator Service (Dropbox download) useful.

Once you have this you can use the list in a separate table with sumif()

9 replies

Mar 2, 2015 2:44 PM in response to Wayne Contello

Hi Wayne


Firstly thank you for the reply and I have downloaded the service and tried to understand how to make use of this.

I need to say right now that I'm a novice on the Mac and not very computer literate.


However, I can now see the service when I enter Numbers/Services and can manually select the cells on which the service operates (in Table 1) and paste the results into my Table 2. However, is it possible to automate this process such that when I add a row to Table 1, the service will run and create unique entries into Table 2? Otherwise, this solution speeds up my manual process, but does not enable me to create Table 2 entries without manually selecting the entries in Table 1.


Regards


Martin

Mar 2, 2015 8:37 PM in response to cervino99

is it possible to automate this process such that when I add a row to Table 1, the service will run and create unique entries into Table 2? Otherwise, this solution speeds up my manual process, but does not enable me to create Table 2 entries without manually selecting the entries in Table 1.


Hi Martin,


I like Pivot Tables too. The service and SUMIF / SUMIFS are about as close as one can get to achieving the same thing in Numbers 3. The manual selection for me provides maximum flexibility and speed; I can extract distinct values from anywhere and them place them anywhere. If you have an unchanging table setup and need to do constant updates that make the quick manual updates burdensome, then a more dedicated script might be worthwhile. If you give more details on your setup I might be able to suggest one. Just as with Pivot Tables it wouldn't be fully automatic, though; you would have to "refresh" by making a menu choice or by hitting a keyboard shortcut.


There are also formula-based methods of extracting distinct values that typically involve adding a "helper" column to your data. These would refresh automatically but can be susceptible to problems when trying to sort. If you are interested in that approach someone here can post an example.


SG

Mar 2, 2015 9:48 PM in response to cervino99

Hello


For instance, you may try something like the following tables.



User uploaded file



Table 1 (excerpt) A1 Surname A2 A A3 B A4 A A5 A B1 Pay B2 10 B3 20 B4 20 B5 10 C1 ordinal C2 =COUNTIF(A$2:A2,A2) C3 =COUNTIF(A$2:A3,A3) C4 =COUNTIF(A$2:A4,A4) C5 =COUNTIF(A$2:A5,A5)



Table 2 (excerpt) A1 Surname A2 =IFERROR(INDEX(Table 1::A,C2,1),"") A3 =IFERROR(INDEX(Table 1::A,C3,1),"") A4 =IFERROR(INDEX(Table 1::A,C4,1),"") A5 =IFERROR(INDEX(Table 1::A,C5,1),"") B1 Total Pay B2 =IF(A<>"",SUMIF(Table 1::A,A2,Table 1::B),"") B3 =IF(A<>"",SUMIF(Table 1::A,A3,Table 1::B),"") B4 =IF(A<>"",SUMIF(Table 1::A,A4,Table 1::B),"") B5 =IF(A<>"",SUMIF(Table 1::A,A5,Table 1::B),"") C1 index C2 =IFERROR(MATCH(1,Table 1::C,0),"") C3 =IFERROR(MATCH(1,OFFSET(Table 1::C,C2,0,ROWS(Table 1::C)-C2,1),0)+C2,"") C4 =IFERROR(MATCH(1,OFFSET(Table 1::C,C3,0,ROWS(Table 1::C)-C3,1),0)+C3,"") C5 =IFERROR(MATCH(1,OFFSET(Table 1::C,C4,0,ROWS(Table 1::C)-C4,1),0)+C4,"")




Notes.


Table 1::C is to record ordinal number per distinct name in Table 1::A.


Table 2::C is to calculate row indices in Table 1::C where its value = 1, i.e., row indices of the 1st appearence of every distinct name in Table 1::A.


Formula in Table 1::C2 can be filled down.


Formula in Table 2::C3 can be filled down.


Formulae in Table 2::A2 and Table 2::B2 can be filled down.


Tables are built in Numbers v2.



Hope this may help,

H


EDIT: fixed notes.

Mar 3, 2015 5:34 PM in response to cervino99

There is also a formula-based approach that requires only one extra column, like this:

User uploaded file


In C2 of Table 1, copied down the column:

=IF(COUNTIF(A$1:A2,A2)=1,MAX(C$1:C1)+1,"")


User uploaded file


In A2 of Table 2, copied down the column:

=IFERROR(INDEX(Table 1::$A,MATCH(ROW()−1,Table 1::$C,0)),""


In B2 of Table 2, copied down the column:

=SUMIF(Table 1::$A,A2,Table 1::$B)


These approaches work. But I find it quicker and easier to use the Copy Distinct Automator Service. Just select cells in Table 1's column A, choose, the service from the Numbers > Service menu, click once in cell A2 of Table 2, and command-v to paste.


SG

Mar 4, 2015 5:07 AM in response to SGIII

Hi SG


Thank you for the time and suggestions. I am now content with using the script and agree it works to about the same level of intervention as Pivot Tables. My only concern would be the longevity of the Service. Can I be confident the Service will continue to function for a good while into the future because I like the solution and want to ensure it's good for me into the future. I'm not a coding expert, far from it, so is this the sort of Service that will stand the test of time, perhaps on through the next operating system and / or Numbers version do you think?


Regards


Martin

Mar 4, 2015 7:39 AM in response to cervino99

Can I be confident the Service will continue to function for a good while into the future because I like the solution and want to ensure it's good for me into the future.


You should be ok with the Service for the foreseeable future. If in the future Apple changes AppleScript support in Numbers in a way that breaks the script, then either I or others here will know how to modify the script. It isn't that elaborate; if it were, I wouldn't know how to code it!


(And going in the other direction, Hiroto could easily change it so that it works with Numbers 2.x; currently it's Numbers 3.x only).


The .workflow package that contains the script is accessible in Finder by holding down the option key, choosing Go from the menu and navigating to Library > Services. Doubleclick 'Copy Distinct.workflow' to open it in Automator and view the script. You can, of course, also delete the Service by going there and trashing it the way you would any other item in Finder.


SG

How do i create a subset of data in numbers 3.5

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