cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Alex19
Level II

Combine Data by Row

Hello, 

I am trying to do the following:

Given Product Column and Lot Column, I need to create "Lots in Product" Column so that it combines all the "lots' based on the same product.

Alex19_0-1733840030799.png

The final purpose is to get the Tabulate:

Alex19_1-1733840281096.png

The X1, X2, X3, X4 does not have to be present in the single cell, this will work as well (whichever is easier):

Alex19_2-1733840342515.png

Manually this process is insane when I have a table of thousands of datapoints.

Thank you so much!

JMP table is attached.

Alex.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jackie_
Level VI

Re: Combine Data by Row

Here is one way

 

Names Default To Here(1);

dt = Current Data Table();	

custom_sql = Eval Insert(
"\[SELECT Product, GROUP_CONCAT(DISTINCT CAST("Lot" as TEXT)) as "Lots in Product"
FROM t1
GROUP BY Product
]\");

dt_concat = Query(
	Table(dt, "t1"),
	custom_sql
);

New window("Tablebox",<<Type("Dialog"),
Data Table Box( dt_concat ));

View solution in original post

4 REPLIES 4
hogi
Level XIII

Re: Combine Data by Row

Very common question.

There are a lot of tricks and workarounds.

 

In a future version of JMP it will be very easy:

:folded_hands: Summary and Tabulate: add aggregation option for Character columns 
... if enough users follow the link and vote.

Jackie_
Level VI

Re: Combine Data by Row

Here is one way

 

Names Default To Here(1);

dt = Current Data Table();	

custom_sql = Eval Insert(
"\[SELECT Product, GROUP_CONCAT(DISTINCT CAST("Lot" as TEXT)) as "Lots in Product"
FROM t1
GROUP BY Product
]\");

dt_concat = Query(
	Table(dt, "t1"),
	custom_sql
);

New window("Tablebox",<<Type("Dialog"),
Data Table Box( dt_concat ));
hogi
Level XIII

Re: Combine Data by Row

another one:

dt = Current Data Table();
dt << New Column( "rank", Formula( Col Rank( 1, :Product ) ), );

dtsplit = dt << Split(
	Split By( :rank ),
	Split( :Lot ),
	Group( :Product ),
	Remaining Columns( Drop All ), 

);

cols = dt split << get column names();
cols = cols[2 :: N Items( cols )];

dt split << New Column( "concat", Character, Set Each value( Concat Items( cols, "," ) ) );

dt << Update(
	With( dt split),
	Match Columns( :Product = :Product ),
	Add Columns from Update Table( :concat ),
	Replace Columns in Main Table( None )
);
Alex19
Level II

Re: Combine Data by Row

Works beautifully! Thank you!

Recommended Articles