cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

How to iterate over a column that has different categorical groups?

Let's say column called Lot has 3 different entries. And that I wanted to add a logic to create a column called "Box Start" that checks which box runs on sequence 1 and copies that information for all entries of that lot in a column called "Box Start" like how it is done below. 

How can I design a for loop to perform this operation?

LotSequenceBoxBox Start
A1aStarts on a
A2bStarts on a
A3Starts on a
A4bStarts on a
B1bStarts on b
B2bStarts on b
B3aStarts on b
B4aStarts on b
B5aStarts on b
C1aStarts on a
C2bStarts on a
C3aStarts on a
1 REPLY 1
txnelson
Super User

Re: How to iterate over a column that has different categorical groups?

Here is one way to solve the problem;  I created a formula that whenever a new value of Lot is found, it calculates when the first occurrence of Lot appeared.

txnelson_0-1680811887335.png

If( :Lot != Lag( :Lot ),
	currLot = :Lot;
	begin = :Box[Min( Current Data Table() << get rows where( :Lot == currLot ) )];
	
);
begin;

If you want to iterate in open code, the following code can be used

For Each Row(
	If( :Lot != Lag( :Lot ),
		currLot = :Lot;
		begin = :Box[Min( Current Data Table() << get rows where( :Lot == currLot ) )];
	);
	Show( begin );
);

 

Jim