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

Put in a list values of a table with condition

I have this table :

dut  |  values

0  | 1638

1  | 618 

2  | 486

3  | 9418

0  | 654

1  | 791 

2  | 1398

3  | 4836

...

 

And I want put in a list, all values where the dut is 0, so have this : list = { 1638, 654 }

What syntax used ?

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Put in a list values of a table with condition

My preferred method is using Data table subscripting with Loc, but there are many other ways to accomplish this

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("dut", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 2, 3, 0, 1, 2, 3])),
	New Column("value", Numeric, "Continuous", Format("Best", 12), Set Values([1638, 618, 486, 9418, 654, 791, 1398, 4836]))
);

zero_rows = Loc(dt[0, "dut"], 0);
list_of_values = dt[zero_rows, "value"]; // and you can convert this to list with As List();
-Jarmo

View solution in original post

txnelson
Super User

Re: Put in a list values of a table with condition

Here is another approach to the same solution

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("dut", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 2, 3, 0, 1, 2, 3])),
	New Column("value", Numeric, "Continuous", Format("Best", 12), Set Values([1638, 618, 486, 9418, 654, 791, 1398, 4836]))
);

theList = As List( :value[dt << get rows where( :dut == 0 )] );

Show( theList );
theList = as list(:value[dt<<get rows where(:dut == 0)])
/*:

{1638, 654}
Jim

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Put in a list values of a table with condition

My preferred method is using Data table subscripting with Loc, but there are many other ways to accomplish this

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("dut", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 2, 3, 0, 1, 2, 3])),
	New Column("value", Numeric, "Continuous", Format("Best", 12), Set Values([1638, 618, 486, 9418, 654, 791, 1398, 4836]))
);

zero_rows = Loc(dt[0, "dut"], 0);
list_of_values = dt[zero_rows, "value"]; // and you can convert this to list with As List();
-Jarmo
txnelson
Super User

Re: Put in a list values of a table with condition

Here is another approach to the same solution

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(8),
	New Column("dut", Numeric, "Continuous", Format("Best", 12), Set Values([0, 1, 2, 3, 0, 1, 2, 3])),
	New Column("value", Numeric, "Continuous", Format("Best", 12), Set Values([1638, 618, 486, 9418, 654, 791, 1398, 4836]))
);

theList = As List( :value[dt << get rows where( :dut == 0 )] );

Show( theList );
theList = as list(:value[dt<<get rows where(:dut == 0)])
/*:

{1638, 654}
Jim