{{ :logo_logo.png?400 |}}
\\
\\
====LESSON 8: Inserting and getting a specific value into a table====
\\
The aim of this lesson is getting and inserting specifics values from and into a table on Dinamica. We will use the [[Get Table Value]], [[Set Table Cell Value]], [[Add Table Column]], [[Set Table By Key]] and [[Get Table From Key]] functors and the following files:
\\
\\
* The IBGE crop information Table (''Guidebook_Dinamica_5\Database\Tables\IBGE_crop_information.csv'')
* The 1999_production_value Table (''Guidebook_Dinamica_5\Database\Tables\1999_production_value.csv'')
* The 1999_harvested_area Table (''Guidebook_Dinamica_5\Database\Tables\1999_harvested_area.csv.csv'')
* The 1999_production Table (''Guidebook_Dinamica_5\Database\Tables\1999_production.csv'')
\\
**Let's go!**
\\
* From the Input/Output tab, grab a [[Load Table]] and place it on the sketch. Double click it, browse to the folder ''Guidebook_Dinamica_5\Database\Tables'' and open the ''IBGE_crop_information.csv'' file.
\\
\\
{{ :imagem32.png?800 |}}
\\
\\
Only multi-column CSV - comma separated value format is accepted
\\
* The first two columns are considered the keys of the file, being used to access a certain data in the table. Click on eye button of [[Load Table]] to see the table.
\\
\\
{{ :imagem33.png?600 |}}
\\
\\
* Grab a [[Get Table Value]] and place it on the sketch. Connect [[Load Table]] to [[Get Table Value]].
\\
\\
{{ :imagem34.png?300 |}}
\\
* Double click the Get Table Value to enter the keys corresponding to the sought-after values and the column name (highlighted by an asterisk). In the box Keys, enter ''2001''. Next, enter ''1'' (The Key to identify the wanted value on the table). Also, in the Column tab, add ''4'', i.e., the column name or index where the value is located.
\\
\\
{{ :imagem35.png?300 |}}
\\
\\
If the given keys are not found in the input table and the __Value If Not Found__ parameter, in the Advanced Tab, is not provided, an error will be reported.
\\
\\
* From the Table tab, grab a [[Calculate Value]] and place it on the sketch. Assign a number to [[Number Value]] and connect the [[Get Table Value]] to [[Number Value]]. In the Connect ports window, select __Value__.
\\
\\
{{ :imagem36.png?600 |}}
\\
\\
* Double-click on [[Calculate Value]] to add a logic or an algebraic expression. We divide v1 (the selected value) by 1000, ''v1/1000'', and click OK.
\\
\\
{{ :imagem37.png?300 |}}
\\
\\
* From the Table tab grab a [[Set Table Cell Value]] and place it on the sketch. Connect [[Calculate Value]] and [[Load Table]] to [[Set Table Cell Value]]. In the Connect Ports window, select __Value__ input port for the output of [[Calculate Value]].
\\
\\
{{ :imagem38.png?600 |}}
\\
\\
* Double-click [[Set Table Cell Value]]. To identify where the sought-after value is located, on the __Keys__ input enter ''2001'', ''1'' (corresponding to Year 2001 and Crop 1) and add the Index ''4'' on the __Column__ input.
\\
\\
{{ :imagem39.png?600 |}}
\\
\\
* From the Input/Output tab, grab a [[Save Table]] and place it on the sketch. Connect [[Set Table Cell Value]] to [[Save Table]], select a folder and chose a file name (e.g. IBGE_crop_information_update.csv). The final model will look like this:
\\
\\
{{ :imagem40.png?600 |}}
\\
\\
{{ :imagem41.png?600 |}}
\\
\\
* Save and run your model. Select the [[Save Table]] functor and click on the eye button to see the result.
\\
\\
{{ :imagem42.png?600 |}}
\\
\\
===Congratulations, you have successfully completed this lesson!===
\\
☞[[:lesson_9 | Next Lesson]]
\\
☞[[:guidebook_start| Back to Guidebook Start]]