cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
user1989
Level I

Looping through a unique items in a column and then tabulate

Hi all,

My data table consists of 3 columns (Name, Hours, and Money).  This is what I wanted to do.

Step 1: Find the unique items in the column "Name". My datatable is dt. Here is what I do.

Summarize(dt, uniqNames = by(:Name));
Show(uniqNames);

This provides me a list

Step 2: For each unique item in the list, I wanted to tabulate the sum of hours and money.   For example, for item A, sum of hours = 24 and sum of money = 10. I want to do the same for item B, C, and D. 

Can I get some help on scripting this?

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Looping through a unique items in a column and then tabulate

I'm not exactly sure what you want to calculate using the tabulate.Basically same thing you would get with Local Data Filter?

jthi_3-1676133918116.png

Is there some specific reason why you wouldn't perform all calculations either with Summarize or Tabulate (or maybe Summary table)? Below are examples:

Tabulate:

jthi_0-1676133628496.png

Summary table:

jthi_1-1676133644841.png

Summarize:

 

Names Default To Here(1);

Summarize(Current Data Table(), names = By(:NAME), sum_hours = Sum(:Hours), sum_money = Sum(:Money));
Show(names, sum_hours, sum_money);

jthi_2-1676133734028.png

 

 

-Jarmo

View solution in original post

txnelson
Super User

Re: Looping through a unique items in a column and then tabulate

I think that all you need to do is to use the Summary Platform.

txnelson_0-1676144124821.png

 

Names Default To Here( 1 );
dt = Current Data Table();

dt << Summary(
	Group( :NAME ),
	Sum( :Hours ),
	Sum( :Money ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" ),
	Link to original data table( 0 )
);
Jim

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Looping through a unique items in a column and then tabulate

I'm not exactly sure what you want to calculate using the tabulate.Basically same thing you would get with Local Data Filter?

jthi_3-1676133918116.png

Is there some specific reason why you wouldn't perform all calculations either with Summarize or Tabulate (or maybe Summary table)? Below are examples:

Tabulate:

jthi_0-1676133628496.png

Summary table:

jthi_1-1676133644841.png

Summarize:

 

Names Default To Here(1);

Summarize(Current Data Table(), names = By(:NAME), sum_hours = Sum(:Hours), sum_money = Sum(:Money));
Show(names, sum_hours, sum_money);

jthi_2-1676133734028.png

 

 

-Jarmo
txnelson
Super User

Re: Looping through a unique items in a column and then tabulate

I think that all you need to do is to use the Summary Platform.

txnelson_0-1676144124821.png

 

Names Default To Here( 1 );
dt = Current Data Table();

dt << Summary(
	Group( :NAME ),
	Sum( :Hours ),
	Sum( :Money ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" ),
	Link to original data table( 0 )
);
Jim