question

Oscar C13 avatar image
0 Likes"
Oscar C13 asked Felix Möhlmann answered

Calculate something in a table

Hi,
I want to multiply 2 columns of a table. I know how to do it, but I would like to know if there are simpler ways.

1. In the attached Model, I wanted multiply "Tiempo" * "Consumo" in the column "Total" in the GlobalTable1. So, I created a tracked variable that stores the value of that multiplication and enter that tracked variable in the table. It works

2. I know that it is possible with a process flow with a code editor but for it to do the opeation it would always have to create an infinite token loop, right? That would not cause problems?

3. I have followed that was said here https://answers.flexsim.com/questions/36805/multiply-two-tables.html

and I have tried to do it so it makes me the same multiplication that I explained before but in the GlobalTable2. The problem is that it only does it at the beginning. Is there a way to do it from here that the multiplication is done constantly?

If there is a more effective way to do it, glad to read you.
Thanks.

MultiplicarTabla.fsm

FlexSim 21.2.2
global table
· 3
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·
Please check if you achieve your aim in a list by dynamic field entries. You can receive those computed values by a list query selecting explicitly this field or by table query of this list as a whole.
0 Likes 0 ·
Oscar C13 avatar image Oscar C13 Joerg Vogel commented ·
Sorry, but I didn´t understand you. If you mean to see if what is done, I can see it from the table.

I may not have explained it well.

What I put are 3 ways that I have found to do the multiplication. In the second one, I simply ask, that being done through a code editor in the process flow, in order for the multiplication to be done constantly, an infinite loop would have to be done.

In the third one, it is only donde either at the beginning or at the end, is there any way to make it dynamic?


0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Oscar C13 commented ·

FlexSim has Lists as a similar structure to tables. Lists behave different then tables. They have an opportunity to evaluate dynamically source code or read updated label values. I suggested you might consider to use this feature.

0 Likes 0 ·

1 Answer

·
Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered

Normally you should only need to update the calculated value when one of the factors changes. You already do this in the trigger of the processor. Although you don't need to save the value to a different variable, you can enter the multiplication directly into the "Value" field of the "Write to Global Table" option.

If the table gets updated from many different points in the model, so adding the trigger to recalculate the value might be tedious you can also use a calculated table. (Tools -> Statistics -> Calculated Table)

This will create a new table that contains the result of the multiplication. You can also add the base columns to it to create a copy of your global table. Calculated tables can be accessed with the same syntax as global tables ("Table(tableName)[row][column]").

multiplicartabla.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.