cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.
  • See how to access JMP Marketplace - and - find, create & share add-ins to extend your JMP. Watch video.

Discussions

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

Count number of unique items in column that meet some criteria

Suppose in "Big Class" I'd like a formula that counts the number of unique names of people at or less than the height of the person in the current row.  How can I do that?

I have this:

thisHeight = :height;
Col N Unique( :name, :height <= thisHeight );

I realize the second parameter is the grouping parameter, and it's more intuitive to try to constrain what gets passed into the first parameter, but I haven't had any luck with anything I've tried to this point.

 

 

1 REPLY 1

Re: Count number of unique items in column that meet some criteria

The closest built in function that comes to mind is Col Rank( :height, <<tie( "maximum" ) ). The problem is: this counts the total number of rows at or below thisHeight, not the number of unique names

Instead, you could try a custom formula, like this: 

 

thisHeight = :height; //store the current height value

// Build an associative array to collect unique names at or below thisHeight
aa = Associative Array();
For( i = 1, i <= N Rows(), i++,
    If( Column("height")[i] <= thisHeight, 
        aa[Column("name")[i]] = 1  // This only adds to the Associative Array if this is a new, unique name
    )
);

// The number of Items that have been added to the array = number of unique names
N Items( aa )

 

 

Recommended Articles