cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-38311%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EF%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38311%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EEstoy%20buscando%20la%20f%C3%B3rmula%20de%20la%20columna%20para%20que%20me%20proporcione%20el%20recuento%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20una%20columna%20(tal%20vez%20en%20funci%C3%B3n%20de%20otras%20categor%C3%ADas%20de%20columnas).%20Por%20ejemplo%2C%20si%20una%20columna%20tiene%3C%2FP%3E%0A%3CP%3EA%3C%2FP%3E%0A%3CP%3EA%3C%2FP%3E%0A%3CP%3EB%3C%2FP%3E%0A%3CP%3EB%3C%2FP%3E%0A%3CP%3EB%3C%2FP%3E%0A%3CP%3EC%3C%2FP%3E%0A%3CP%3Eentonces%20me%20gustar%C3%ADa%20recuperar%20el%20valor%203.%3C%2FP%3E%0A%3CP%3EGracias%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55334%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55334%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%22Por%22%20es%20un%20concepto%20bastante%20global%20en%20JMP.Si%20ejecuta%20la%20plataforma%20de%20distribuci%C3%B3n%20y%20especifica%20una%20variable%20%22Por%22%2C%20generar%C3%A1%20una%20distribuci%C3%B3n%20separada%20para%20cada%20uno%20de%20los%20diferentes%20valores%20de%20las%20columnas%20%22Por%22.Lo%20mismo%20es%20para%20la%20funci%C3%B3n%20Summarize().Aqu%C3%AD%20hay%20una%20cita%20de%20la%20referencia%20de%20sintaxis%20JSL%20para%20la%20funci%C3%B3n%20Summarize().%3C%2FP%3E%0A%3CP%3EAyuda%3D%3D%26gt%3BLibros%3D%3D%26gt%3BReferencia%20de%20sintaxis%20JSL%3C%2FP%3E%0A%3CP%3E%22Usar%20una%20variable%20BY%20cambia%20la%20salida%20de%20valores%20%C3%BAnicos%20para%20cada%20estad%C3%ADstica%20a%20una%20lista%20de%20valores%20para%20cada%20grupo%20en%20la%20variable%20BY%22.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETambi%C3%A9n%20se%20puede%20encontrar%20buena%20documentaci%C3%B3n%20junto%20con%20un%20ejemplo%20en%20el%20%C3%ADndice%20de%20secuencias%20de%20comandos%3C%2FP%3E%0A%3CP%3EAyuda%3D%3D%26gt%3B%C3%8Dndice%20de%20secuencias%20de%20comandos%3D%3D%26gt%3BFunciones%3D%3D%26gt%3BEstad%C3%ADsticas%3D%3D%26gt%3BResumir%3C%2FP%3E%0A%3CP%3Eo%3C%2FP%3E%0A%3CP%3EAyuda%3D%3D%26gt%3B%C3%8Dndice%20de%20secuencias%20de%20comandos.........buscar%20en%20Resumir%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55330%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55330%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ESr.%20Nelson%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%C2%BFPuede%20describir%20en%20detalle%20lo%20que%20est%C3%A1%20haciendo%20esta%20funci%C3%B3n%3F%20No%20estoy%20seguro%20de%20entender%20la%20funci%C3%B3n%20%22por%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGracias%2C%3C%2FP%3E%3CP%3EMart%C3%ADn%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55305%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55305%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C2%A1Eso%20funcion%C3%B3%20muy%20bien!%20Me%20desconcert%C3%B3%20el%20subrayado%20rojo%2C%20pens%C3%A9%20que%20eso%20significaba%20que%20no%20iba%20a%20funcionar.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20466px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20466px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20466px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F10453i279D01A72CFCF8B1%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEn%20realidad%2C%20no%20estoy%20seguro%20de%20haber%20intentado%20pegar%20una%20f%C3%B3rmula%20directamente%20en%20la%20columna%20antes%2C%20pens%C3%A9%20que%20ten%C3%ADa%20que%20reconstruirla%20usando%20las%20funciones%20de%20columna%20de%20f%C3%B3rmula%20expl%C3%ADcitas...%20esta%20es%20una%20gran%20mejora.%20%C2%A1Muchas%20Gracias%20por%20la%20r%C3%A1pida%20respuesta!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ear%C3%B3n%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55292%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55292%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELo%20que%20siempre%20olvido%20es%20que%20una%20f%C3%B3rmula%20de%20columna%20en%20realidad%20puede%20ser%20un%20mini%20script%20completo%3B%20con%20muchos%20puntos%20y%20comas%20y%20l%C3%ADneas%20de%20c%C3%B3digo.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55284%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55284%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20f%C3%B3rmula%20indicada%20de%20mi%20%C3%BAltima%20respuesta%20deber%C3%ADa%20hacer%20lo%20que%20quieras.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20%3D%3D%201%2C%0A%20Summarize(%20x%20%3D%20by(%20%3ACustomer_ID)%20)%3B%0A%20y%20%3D%20N%20Items(%20x%20)%3B%0A)%3B%0Ay%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESolo%20corta%20y%20pega%20esto%20en%20el%20editor%20de%20f%C3%B3rmulas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EVeo%20c%C3%B3mo%20funcionar%C3%ADa%20esto%20para%20un%20script%20para%20crear%20una%20columna%2C%20pero%20he%20creado%20una%20tabla%20de%20datos%20que%20actualizo%20desde%20una%20base%20de%20datos%20y%20me%20gustar%C3%ADa%20tener%20una%20columna%20en%20esa%20tabla%20con%20una%20f%C3%B3rmula%20para%20calcular%20la%20cantidad%20de%20categor%C3%ADas%20%C3%BAnicas.%20%C2%BFHay%20alguna%20forma%20de%20hacerlo%20directamente%20en%20una%20f%C3%B3rmula%20de%20columna%20en%20lugar%20de%20hacerlo%20mediante%20un%20script%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEncontr%C3%A9%20un%20truco%20usando%20Def()%20y%20Col%20Sum%2C%20pero%20solo%20funciona%20porque%20estoy%20viendo%20un%20campo%20ordenado%20que%20es%20una%20identificaci%C3%B3n%20%C3%BAnica%20con%20n%C3%BAmeros.%20No%20funciona%20para%20variables%20de%20texto%20reales.%20%C2%BFHay%20una%20mejor%20soluci%C3%B3n%20para%20eso%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAqu%C3%AD%20est%C3%A1%20la%20f%C3%B3rmula%20pirateada%3A%3C%2FP%3E%3CP%3ECol%20Sum(%20Dif(%20%3Acustomer_id%20)%20%26gt%3B%200%20)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGracias%2C%3C%2FP%3E%3CP%3Ear%C3%B3n%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-38489%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38489%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%A1Esto%20es%20perfecto!%20%C2%A1Gracias%20Jim!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-38313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPruebe%20esta%20f%C3%B3rmula%20.......%20por%20supuesto%2C%20cambie%20%3AFlow%20por%20la%20columna%20para%20la%20que%20desea%20contar%20las%20categor%C3%ADas%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ESummarize(%20x%20%3D%20by(%20%3AFLOW%20)%20)%3B%0AN%20Items(%20x%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ESi%20la%20tabla%20de%20datos%20es%20realmente%20grande%2C%20es%20posible%20que%20desee%20utilizar%20esta%20versi%C3%B3n%20m%C3%A1s%20eficiente%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Row()%20%3D%3D%201%2C%0A%20Summarize(%20x%20%3D%20by(%20%3AFlow%20)%20)%3B%0A%20y%20%3D%20N%20Items(%20x%20)%3B%0A)%3B%0Ay%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-38312%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20F%C3%B3rmula%20para%20el%20n%C3%BAmero%20de%20categor%C3%ADas%20%C3%BAnicas%20en%20la%20columna%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38312%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECreo%20recordar%20que%20se%20us%C3%B3%20la%20f%C3%B3rmula%20de%20Sumatoria%20para%20esto%2C%20pero%20mi%20memoria%20me%20falla.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Martin
Level V

Formula for Number of Unique Categories in Column

I am looking for the column formula to provide me with the count of unique categories in a column (maybe based on another columns categories). For instance, if a column has

A

A

B

B

B

C

then I would like to get back the value 3.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Formula for Number of Unique Categories in Column

Try this formula.......of course, swap out the :Flow for the column you want to count the categories for

Summarize( x = by( :FLOW ) );
N Items( x );

If the data table is really large, you may want to use this more efficient version

If( Row() == 1,
	Summarize( x = by( :Flow ) );
	y = N Items( x );
);
y;

 

Jim

View solution in original post

9 REPLIES 9
Martin
Level V

Re: Formula for Number of Unique Categories in Column

I think I remember the Summation formula being used for this, but my memory fails me.

txnelson
Super User

Re: Formula for Number of Unique Categories in Column

Try this formula.......of course, swap out the :Flow for the column you want to count the categories for

Summarize( x = by( :FLOW ) );
N Items( x );

If the data table is really large, you may want to use this more efficient version

If( Row() == 1,
	Summarize( x = by( :Flow ) );
	y = N Items( x );
);
y;

 

Jim
Martin
Level V

Re: Formula for Number of Unique Categories in Column

This is PERFECT! Thank you Jim!
aronwilson
Level II

Re: Formula for Number of Unique Categories in Column

I see how this would work for a script to create a column, but I've created a datatable that I update from a database and I'd like to have a column in that table with a formula to calculate the number of unique categories. Is there a way to do that directly in a column formula instead of though a script?

 

I found a hack using using Def() and Col Sum but it only works because i'm looking at a sorted field that's a unique id with numbrers. It doesn't work for actual text variables. Is there a better solution for that?

 

Here is the hacked formula:

Col Sum( Dif( :customer_id ) > 0 )

 

Thank you,

Aron

txnelson
Super User

Re: Formula for Number of Unique Categories in Column

The stated formula from my last response should do what you want.  

If( Row() == 1,
	Summarize( x = by( :Customer_ID) );
	y = N Items( x );
);
y;

Just cut and paste this into the formula editor

Jim
Martin
Level V

Re: Formula for Number of Unique Categories in Column

What I always forget, is that a column formula can actually be an entire mini script; with many semicolons and lines of code.

aronwilson
Level II

Re: Formula for Number of Unique Categories in Column

That worked great! I was thrown off by the red underline, I thought that meant it wasn't going to work.

image.png

 

I'm not actually sure I've ever tried pasting a formula directly in the column before, I thought I had to rebuild it using the explicit formula column functions... this is a huge improvement. Thank you so much for the quick reply!

 

Aron

Martin
Level V

Re: Formula for Number of Unique Categories in Column

Mr. Nelson,

 

Can you describe in detail what this function is doing? Not sure I understand the "by" function.

 

Thanks,

Martin

txnelson
Super User

Re: Formula for Number of Unique Categories in Column

"By" is a fairly global concept in JMP.  If you run the Distribution Platform, and specify a "By" variable it will generate a separate Distribution for each of the different values of the "By" columns.  The same is for the Summarize() function.  Here is a quote from the JSL Syntax Reference for the Summarize() function.

     Help==>Books==>JSL Syntax Reference

"Using a BY variable changes the output from single values for each statistic to a list of values for each group in the BY variable."

 

Good documentation along with an example can also be fount in the Scripting Index

     Help==>Scripting Index==>Functions==>Statistical==>Sumarize

or

     Help==>Scripting Index.........search on Summarize

Jim

Recommended Articles