question

Suraj J avatar image
0 Likes"
Suraj J asked Joerg Vogel answered

Return value from second column based on value queried.

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
.5 150
.75 175
1.0 190

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

Any help is appreciated.

global tablelookup
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Joerg Vogel commented

@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")[i][1] >= value)
	{
		return Table[i][2];
	}
}
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Suraj J avatar image Suraj J commented ·

I guess I have to take this route then.

0 Likes 0 ·
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

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];

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


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.