Audience: C#/.NET developers (beginners included)
Following examples can be found and executed in the Microsoft Visual Studio file FinaquantCalcsStarter with demo functions for training.

Define all fields centrally in MetaData
Fields of all tables must be first defined centrally in a MetaData object.
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // define metadata
- md = MetaData.CreateEmptyMetaData();
- MetaData.AddNewField(md, "category", FieldType.TextAttribute);
- MetaData.AddNewField(md, "product", FieldType.TextAttribute);
- MetaData.AddNewField(md, "brand", FieldType.TextAttribute);
- MetaData.AddNewField(md, "costs", FieldType.KeyFigure);
- MetaData.AddNewField(md, "price", FieldType.KeyFigure);
- MetaData.AddNewField(md, "margin", FieldType.KeyFigure);
- GeSHi ©
Create Cost and Margin tables manually for the examples below
Before creating a table of type MatrixTable (which can be converted to DataTable of .NET) its fields must be defined.
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // define table structure for CostTable
- var CostTableFields = TableFields.CreateEmptyTableFields(md);
- TableFields.AddNewField(CostTableFields, "category");
- TableFields.AddNewField(CostTableFields, "brand");
- TableFields.AddNewField(CostTableFields, "product");
- TableFields.AddNewField(CostTableFields, "costs");
- // create CostTable with elements
- CostTable = MatrixTable.CreateTableWithElements_A(CostTableFields,
- "Notebook", "Ignor", "Ignor UX Notebook", 850.0,
- "Notebook", "Ignor", "Ignor AX Notebook", 950.0,
- "Notebook", "Euphor", "Euphor 5 Notebook", 1200.0,
- "Notebook", "Euphor", "Euphor 10 Notebook", 1450.0,
- "Desktop", "Ignor", "Ignor 4D Desktop", 650.0,
- "Desktop", "Ignor", "Ignor 6D Desktop", 800.0,
- "Desktop", "Euphor", "Euphor 2E Desktop", 1050.0,
- "Desktop", "Euphor", "Euphor 5E Desktop", 1300.0
- );
- // define table structure for MarginTable1
- var MarginTable1Fields = TableFields.CreateEmptyTableFields(md);
- TableFields.AddNewField(MarginTable1Fields, "category");
- TableFields.AddNewField(MarginTable1Fields, "margin");
- // create MarginTable1 with elements
- MarginTable1 = MatrixTable.CreateTableWithElements_A(MarginTable1Fields,
- "Notebook", 0.40,
- "Desktop", 0.30
- );
- // define table structure for MarginTable2
- var MarginTable2Fields = TableFields.CreateEmptyTableFields(md);
- TableFields.AddNewField(MarginTable2Fields, "category");
- TableFields.AddNewField(MarginTable2Fields, "brand");
- TableFields.AddNewField(MarginTable2Fields, "margin");
- // create MarginTable1 with elements
- MarginTable2 = MatrixTable.CreateTableWithElements_A(MarginTable2Fields,
- "Notebook", "Ignor", 0.40,
- "Desktop", "Ignor", 0.30,
- "Notebook", "Euphor", 0.45,
- "Desktop", "Euphor", 0.35
- );
- GeSHi ©
Note that the order of fields in a MatrixTable is important. Fields must be defined and assigned in this order:
TextAttribute, IntegerAttribute, DateAttribute, KeyFigure
Example 1: View cost and margin tables with table viewer
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // view cost table
- MatrixTable.View_MatrixTable(CostTable, "Cost table");
- // view margin tables
- MatrixTable.View_MatrixTable(MarginTable1, "MarginTable1");
- MatrixTable.View_MatrixTable(MarginTable2, "MarginTable2");
- GeSHi ©

Example 2: Round all numbers (key figures) in table
In this example we have two table functions:
1) table-scalar multiplication (CostTable * 1.3333)
2) Round all key figures (MatrixTable.Round)
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // All key figures are already round!
- // Let's add some decimal fractions to costs
- MatrixTable CostTable_fractions = CostTable * 1.3333;
- // view table with fractional numbers
- MatrixTable.View_MatrixTable(CostTable_fractions, "Cost table with fractional costs");
- // round numbers to 2 digits after decimal point
- MatrixTable CostTable_rounded = MatrixTable.Round(CostTable_fractions, 2);
- // view table with rounded numbers
- MatrixTable.View_MatrixTable(CostTable_rounded, "Cost table with rounded costs");
- GeSHi ©

Example 3: Obtain price table with MarginTable1
This is a classical example for table multiplication. Note that (MarginTable1 + 1) is table-scalar addition; 1 is added to all key figures of MarginTable1
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // MarginTable1 specifies margins per category
- MatrixTable PriceTable1 = MatrixTable.MultiplySelectedKeyFigures(CostTable, (MarginTable1 + 1),
- InputKeyFigTbl1: "costs", InputKeyFigTbl2: "margin", OutputKeyFig: "price");
- // view PriceTable1
- MatrixTable.View_MatrixTable(PriceTable1, "PriceTable1: Prices calculated with margins per category");
- GeSHi ©
In this example, price margins are determined by category only as given in MarginTable1 above.

Example 3: Obtain price table with MarginTable2
In this example, price margins are determined by category and brand as given in MarginTable2 above.
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- // MarginTable2 specifies margins per category and brand
- MatrixTable PriceTable2 = MatrixTable.MultiplySelectedKeyFigures(CostTable, (MarginTable2 + 1),
- InputKeyFigTbl1: "costs", InputKeyFigTbl2: "margin", OutputKeyFig: "price");
- // view PriceTable1
- MatrixTable.View_MatrixTable(PriceTable2, "PriceTable2: Prices calculated with margins per category and brand");
- GeSHi ©

In the examples above, the cost table has only three attributes; category, brand and product. The table functions above wouldn't change even if cost table had 12 attributes and margin tables had 10 of them; all the statements would still be valid.
The only condition that must be satisfied for the table multiplication is this: The attributes of the second table (MarginTable in our case) must be a subset of the attributes of the first table (CostTable). In other words, attributes of the second table must be contained by the attributes of the second table.
The beauty of table functions is in their generality; they can be applied to (almost) any table with any field structure. Once you get used to the generality of table functions, you start to think more about the analytical operation itself rather than the field structure of individual tables.
An analogy: Two matrices of any size can be multiplied (matrix multiplication) provided only that column-count of the first matrix is equal to row-count of second matrix.