cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

How Do I create a Column formula for N Categories?

trish_roth
Level III

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 XII


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 XII


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 XII


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:

Scoping_NUnique.mp4
Video Player is loading.
Current Time 0:00
Duration 0:14
Loaded: 0%
Stream Type LIVE
Remaining Time 0:14
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
    • en (Main), selected
    (view in My Videos)


    ... there may be more useful applications : )

     

    hogi
    Level XII


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

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