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%3EFormule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38311%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJe%20recherche%20la%20formule%20de%20colonne%20pour%20me%20fournir%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20une%20colonne%20(peut-%C3%AAtre%20bas%C3%A9e%20sur%20d'autres%20cat%C3%A9gories%20de%20colonnes).%20Par%20exemple%2C%20si%20une%20colonne%20a%3C%2FP%3E%0A%3CP%3EUN%3C%2FP%3E%0A%3CP%3EUN%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%3Ealors%20je%20voudrais%20r%C3%A9cup%C3%A9rer%20la%20valeur%203.%3C%2FP%3E%0A%3CP%3EMerci%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55334%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%22Par%22%20est%20un%20concept%20assez%20global%20dans%20JMP.Si%20vous%20ex%C3%A9cutez%20la%20plate-forme%20de%20distribution%20et%20sp%C3%A9cifiez%20une%20variable%20%22By%22%2C%20elle%20g%C3%A9n%C3%A9rera%20une%20distribution%20distincte%20pour%20chacune%20des%20diff%C3%A9rentes%20valeurs%20des%20colonnes%20%22By%22.Il%20en%20va%20de%20m%C3%AAme%20pour%20la%20fonction%20Summarize().Voici%20une%20citation%20de%20la%20r%C3%A9f%C3%A9rence%20de%20syntaxe%20JSL%20pour%20la%20fonction%20Summarize().%3C%2FP%3E%0A%3CP%3EAide%3D%3D%26gt%3BLivres%3D%3D%26gt%3BR%C3%A9f%C3%A9rence%20de%20la%20syntaxe%20JSL%3C%2FP%3E%0A%3CP%3E%22L'utilisation%20d'une%20variable%20BY%20modifie%20la%20sortie%20de%20valeurs%20uniques%20pour%20chaque%20statistique%20en%20une%20liste%20de%20valeurs%20pour%20chaque%20groupe%20dans%20la%20variable%20BY.%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUne%20bonne%20documentation%20ainsi%20qu'un%20exemple%20peuvent%20%C3%A9galement%20%C3%AAtre%20trouv%C3%A9s%20dans%20l'index%20de%20script%3C%2FP%3E%0A%3CP%3EAide%3D%3D%26gt%3BIndex%20des%20scripts%3D%3D%26gt%3BFonctions%3D%3D%26gt%3BStatistiques%3D%3D%26gt%3BR%C3%A9sumer%3C%2FP%3E%0A%3CP%3Eou%3C%2FP%3E%0A%3CP%3EAide%20%3D%3D%26gt%3B%20Index%20des%20scripts%20.........%20recherche%20sur%20R%C3%A9sumer%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55330%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EMonsieur%20Nelson%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPouvez-vous%20d%C3%A9crire%20en%20d%C3%A9tail%20ce%20que%20fait%20cette%20fonction%26nbsp%3B%3F%20Je%20ne%20suis%20pas%20s%C3%BBr%20de%20comprendre%20la%20fonction%20%22by%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMerci%2C%3C%2FP%3E%3CP%3EMartin%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55305%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECela%20a%20tr%C3%A8s%20bien%20fonctionn%C3%A9%26nbsp%3B!%20J'ai%20%C3%A9t%C3%A9%20d%C3%A9concert%C3%A9%20par%20le%20soulignement%20rouge%2C%20je%20pensais%20que%20cela%20signifiait%20que%20cela%20n'allait%20pas%20fonctionner.%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%3EJe%20ne%20suis%20pas%20s%C3%BBr%20d'avoir%20d%C3%A9j%C3%A0%20essay%C3%A9%20de%20coller%20une%20formule%20directement%20dans%20la%20colonne%20auparavant%2C%20je%20pensais%20que%20je%20devais%20la%20reconstruire%20en%20utilisant%20les%20fonctions%20explicites%20de%20colonne%20de%20formule%20...%20c'est%20une%20%C3%A9norme%20am%C3%A9lioration.%20Merci%20beaucoup%20pour%20la%20r%C3%A9ponse%20rapide!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EArron%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55292%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECe%20que%20j'oublie%20toujours%2C%20c'est%20qu'une%20formule%20de%20colonne%20peut%20en%20fait%20%C3%AAtre%20un%20mini%20script%20entier%20%3B%20avec%20de%20nombreux%20points-virgules%20et%20lignes%20de%20code.%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55284%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ELa%20formule%20indiqu%C3%A9e%20de%20ma%20derni%C3%A8re%20r%C3%A9ponse%20devrait%20faire%20ce%20que%20vous%20voulez.%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%3EIl%20suffit%20de%20couper%20et%20coller%20ceci%20dans%20l'%C3%A9diteur%20de%20formule%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55272%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJe%20vois%20comment%20cela%20fonctionnerait%20pour%20un%20script%20pour%20cr%C3%A9er%20une%20colonne%2C%20mais%20j'ai%20cr%C3%A9%C3%A9%20une%20table%20de%20donn%C3%A9es%20que%20je%20mets%20%C3%A0%20jour%20%C3%A0%20partir%20d'une%20base%20de%20donn%C3%A9es%20et%20j'aimerais%20avoir%20une%20colonne%20dans%20cette%20table%20avec%20une%20formule%20pour%20calculer%20le%20nombre%20de%20cat%C3%A9gories%20uniques.%20Existe-t-il%20un%20moyen%20de%20le%20faire%20directement%20dans%20une%20formule%20de%20colonne%20au%20lieu%20d'un%20script%26nbsp%3B%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJ'ai%20trouv%C3%A9%20un%20hack%20en%20utilisant%20Def()%20et%20Col%20Sum%20mais%20cela%20ne%20fonctionne%20que%20parce%20que%20je%20regarde%20un%20champ%20tri%C3%A9%20qui%20est%20un%20identifiant%20unique%20avec%20des%20num%C3%A9ros.%20Cela%20ne%20fonctionne%20pas%20pour%20les%20variables%20de%20texte%20r%C3%A9elles.%20Existe-t-il%20une%20meilleure%20solution%20pour%20cela%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EVoici%20la%20formule%20pirat%C3%A9e%20%3A%3C%2FP%3E%3CP%3ECol%20Sum(%20Dif(%20%3Aid_client%20)%20%26gt%3B%200%20)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMerci%2C%3C%2FP%3E%3CP%3EArron%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38489%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3EC'est%20parfait!%20Merci%20Jim!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-38313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38313%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EEssayez%20cette%20formule%20.......%20bien%20s%C3%BBr%2C%20remplacez%20le%20%3AFlow%20par%20la%20colonne%20pour%20laquelle%20vous%20souhaitez%20compter%20les%20cat%C3%A9gories%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%20le%20tableau%20de%20donn%C3%A9es%20est%20vraiment%20volumineux%2C%20vous%20pouvez%20utiliser%20cette%20version%20plus%20efficace%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%26nbsp%3B%3A%20Formule%20pour%20le%20nombre%20de%20cat%C3%A9gories%20uniques%20dans%20la%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-38312%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EJe%20pense%20que%20je%20me%20souviens%20de%20la%20formule%20de%20sommation%20utilis%C3%A9e%20pour%20cela%2C%20mais%20ma%20m%C3%A9moire%20me%20fait%20d%C3%A9faut.%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