For conditional calculation, JMP provides the Col XYZ() aggregation functions.
For counting, you can use Col Number(). It counts any non-missing entry.
To convert non-matching rows to "missing", you need something like Col sum (if(Rank_ASC==1 ,1,.),:Part_Number).
If Rank is 1, the if expression returns 1, for the other rows, it will return "." (missing) - and JMP doesn't count the row.
After a first argument for the numeric input, you can specify additional columns (and expressions) to specify byGroups.
With :Part_Number as the second argument, JMP will create separate counts for each :Part_Number.
I prefer Col Sum().
To count specific rows, you can use a comparison like Col sum (Rank_ASC==1 , :Part_Number ).
The idea behind the expression:
For rows with rank 1, the result of the comparison Rank_ASC==1 is 1, for the other rows the result is 0.
So, col sum will count all rows with rank=1.
Here, we use again :Part_Number as a second argument. So, counts will be separate for the different Part_Numbers.
New Table( "parts",
Add Rows( 7 ),
New Column( "ID",
Character,
Set Values( {"U30372", "W30569", "W30569", "Q40040", "P40051", "P40051", "P40051"} )
),
New Column( "Part_Number",
Character,
Set Values( {"T772", "T772", "T772", "T772", "T770", "T772", "T770"} )
),
New Column( "Rank_ASC", Formula( Col Rank( :Part_Number, :ID ) ) ),
New Column( "PN_Count_Rank_ASC",
Formula( Col Sum( :Rank_ASC == 1, :Part_Number ) ),
Set Display Width( 156 )
),
New Column( "RANK_DESC",
Formula( (Col Number( :Part_Number, :ID ) - Col Rank( :Part_Number, :ID )) + 1 )
),
New Column( "PN_Count_Rank_DESC", Formula( Col Sum( :RANK_DESC == 1, :Part_Number ) ) )
)