Here is one way to solve your issue.
Here is the formula I used
If( Row() == 1 | Lag( :ITEM ) != :ITEM,
currentItem = :ITEM;
theRows = Current Data Table() << get rows where( :ITEM == currentItem );
For( i = 1, i <= N Rows( theRows ), i++,
theRows[i] = :ID[theRows[i]]
);
r = Rank( theRows );
theValues = theRows[r];
Remove From( theValues, 7, 9999999 );
);
If( N Rows( Loc( theValues, :ID ) ) > 0,
"Y",
""
);
I have attached the sample data table shown above
Jim