cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

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

How Do I create a Column formula for N Categories?

I would like to create a column formula that provides a count of the number of distinct values in a column.  I can use the Column viewer, Show summary function in JMP 15 but I want to have that value in a column for use in other calculations.

 

For example in the Big Class Table - N Items in column "Sex" should show 2 as 2 distinct values.

14 REPLIES 14
hogi
Level XIII

Re: How Do I create a Column formula for N Categories?

here is a wish to add such a functionality
... to JSL
... to New Column Formula
... to Graph Builder

Col N Categories 

I guess there are only a few JMP users in the world who don't need it ; )
Most JMP users will be excited to see such a functionality in a future version of JMP (... along with dense ranking )

wgardnerQS
Level III

Re: How Do I create a Column formula for N Categories?

A little late to the thread, but I was looking for a solution to the same problem.  The formula below in @CTrahon0526 's datatable reproduces the values in "Unique Tool IDs Per Work Week Per Year" column

Col Sum( Col Cumulative Sum( 1, :Year, :WW, :Tool ID ) == 1, :Year, :WW )
hogi
Level XIII

Re: How Do I create a Column formula for N Categories?

Nice, I can use this a lot - so, now I have:

Names Default To Here( 1 );
Try(dt = CurrentDataTable(), stop());


updateLBox = Function( {t},
	(t << sib) << setitems( (t << topparent)[listboxbox( 1 )] << getselected )
);

nw = New Window("count unique entries",
<< Type("Modal Dialog"),
	Border Box( Left( 10 ), Right( 10 ), bottom( 5 ),
		V List Box(
			Lineup Box( N Col( 1 ), spacing( 10 ),
				// Text Box( "XG Boost Specification" ), 
				// colistbox only necessary if the script is standalone
				H List Box(
					Panel Box( "Select Columns", Col List Box( all, nlines( 15 ) ) ),
					Panel Box( "Cast Selected Columns into Roles",
						Lineup Box( N Col( 2 ),
							Button Box("Unique",
								<<setfunction( Function( {t}, updateLBox( t ) ) )
							),
							Cunique = Col List Box( nlines( 2 ), minitems( 1 ) ),
							Button Box("By Group",
								<<setfunction( Function( {t}, updateLBox( t ) ) )
							),
							CBy = Col List Box( nlines( 2 ), minitems( 0 ) )
						)
					)
				)
			),
			spacerbox(size(1,10)),
			Button Box( "OK",
				<<setfunction(
					Function({t}, ColsUnique = Cunique << get items;ColsBy= Cby << get items)
				)
			),
			spacerbox(size(1,10)),
		)
	)
);

ccs= Expr(Col Cumulative Sum( 1));
for each ({col}, ColsUnique, Insert Into(ccs, Name Expr(As column(col))));
for each ({col}, ColsBy, Insert Into(ccs, Name Expr(As column(col))));
cs = Eval Expr(Col Sum( Expr(Eval Expr(Expr(Name Expr(ccs)) == 1 ))));
for each ({col}, ColsBy, Insert Into(cs, Name Expr(As column(col))));

Eval (Eval Expr(new column ("unique_"|| concat items (ColsUnique,"_"),
	Formula(Expr(Name Expr(cs))))))
	

... available at a single mouse click : )

hogi
Level XIII

Re: How Do I create a Column formula for N Categories?

to get the next level of interactivity - please vote here:
Transform Columns - as comfortable as Summary Statistics? 

e.g. to show the number of car makers - correct values for individual years - and split by door size:

(view in My Videos)


... there may be more useful applications : )

 

:)

hogi
Level XIII

Re: How Do I create a Column formula for N Categories?

[removed] didn't show up at the right position.

Recommended Articles