Table fields: Text and numeric attributes, key figures

Table fieldsA table represented by a MatrixTable object in calculation engine libraries (finaquant® protos or finaquant® calcs) can have three types of fields: Text attributes, numeric attributes and key figures.

Text attributes contain values of data type string (text) like “Computer”. Numeric attributes are stored as integer numbers like 675. Key figures (or numbers) are stored as floating numbers like 150.25. Note that dates like 20/10/2010 are stored as numeric attributes in the form of serial day numbers (i.e. total number of days since 30.12.1899).

Attributes and numbersAttributes and numbers have different roles in a table. Attributes are used for the identification (like product_id) or categorization (like product category) of data. Numbers (key figures) are measures and amounts like price, weight and quantity. The difference between numeric attributes and key figures is a subtle one: Generally, it makes sense to apply arithmetic operations like addition and multiplication on key figures, but not on numeric attributes. As mentioned before, attributes are there for identification and classification; not for arithmetic operations.

For conversion and formatting purposes, date and non-date numeric attributes are differentiated as date attributes and integer attributes in MetaData. However, this distinction is not required for elementary table functions.

Press F5 to execute the script in Visual Studio (create table)Having described field types let’s see a) how fields are defined in MetaData, and b) how a table containing a subset of these fields are created with the functions available in calculation engine libraries:

// define fields in MetaData
// Note: All available fields must be defined centrally in MetaData
// ... before creating tables with a subset of these fields
var md = MetaData.CreateEmptyMasterData();
MetaData.AddNewField(md, "category", FieldType.TextAttribute);
MetaData.AddNewField(md, "product_name", FieldType.TextAttribute);
MetaData.AddNewField(md, "product_id", FieldType.IntegerAttribute);
MetaData.AddNewField(md, "date", FieldType.DateAttribute);
MetaData.AddNewField(md, "sales_eur", FieldType.KeyFigure);
// create table with the fields defined above in MetaData
// first, define table structure
var tfields = TableFields.CreateEmptyTableFields(md);
TableFields.AddNewField(tfields, "category");
TableFields.AddNewField(tfields, "product_name");
TableFields.AddNewField(tfields, "product_id");
TableFields.AddNewField(tfields, "date");
TableFields.AddNewField(tfields, "sales_eur");
// add entries (i.e. values) to table
var MyTable = MatrixTable.CreateTableWithElements_A(tfields,
"Computer", "AIX Notebook", 670, DateFunctions.DayToNumber(20,10,2010), 150.25,
"Computer", "AIX Desktop", 675, DateFunctions.DayToNumber(25,10,2010), 250.10
// display table in immediate window
System.Diagnostics.Debug.WriteLine("tbl = \n" + MyTable);
Copyright secured by Digiprove © 2012 Tunc Ali Kütükcüoglu

Leave a Reply