Return value from second column based on value queried.

Return value from second column based on value queried.

suraj_j
Not applicable
58 Views
3 Replies
Message 1 of 4

Return value from second column based on value queried.

suraj_j
Not applicable

Hello

I can't recollect if there is a function that returns a value from 2nd column of global table based on value that is given in first column.

e.g. From following data, if I enter 'SomeFunc("Table",0.8) I would get 190 (rounded above).

.25
100
.5150
.75175
1.0190

I know about d/c/empirical. The number in first column is not random but calculated.

Any help is appreciated.

0 Likes
Accepted solutions (1)
59 Views
3 Replies
Replies (3)
Message 2 of 4

SCHamoen
Advisor
Advisor
Accepted solution

@Suraj J

As far as I know there is not. But it is very simple to create your own usercommand and have this function. Something like this would do:

double value = param(1);

for( int i = 1; i <= Table("TheTable").numrows; i++ )
{
	if( Table("TheTable")[1] >= value)
	{
		return Table[2];
	}
}
0 Likes
Message 3 of 4

suraj_j
Not applicable

I guess I have to take this route then.

0 Likes
Message 4 of 4

joerg_vogel_HsH
Mentor
Mentor

You get your return value by an Table.query.

Table.query("SELECT target FROM TheTable WHERE input >= $1 ORDER BY input ASC", col1Value)[1][1];

12321-returnvalue-from-table-by-query.jpg

The Reset trigger contains more lines of code, because I want to show how you get the value. Line 7 is the code you need. Attached is the model in Flexsim 18.1.1.

query-table-for-return.fsm

0 Likes