Different operations on numbers depending on attributes

Table-valued functions in finaquant .net libraries

Different operations on numbers depending on attributes

Postby ariston » 20 Oct 2013, 14:05

Hi,

i want to apply different operations on numeric fields of a table depending on attribute values.

for example, take square of a field named price if the color is red, take square root if color is blue, etc.

is this possible with table functions of finaquant's library?
Arin
ariston
 
Posts: 6
Joined: 20 Oct 2013, 13:51

Re: Row Transformation Function (row-by-row processing)

Postby finaquant » 22 Oct 2013, 09:25

There are several ways to apply mathematical operations on selected key figures (number fields) depending on attribute values, using table functions of .Net libraries finaquant protos (non-commercial) or finaquant calcs (commercial).

The easiest way to do it is using the table function for row-by-row processing: MatrixTable.TransformRowsDic()

You may find examples in Demo Function named Row_by_Row_processing_of_table in Visual Studio files FinaquantProtosStarter or FinaquantCalcsStarter that you can download at the corresponding product page.
Image

Related HELP page: Table transformation functions (see transforming rows of a table with dictionary)

In your case the row transformation function of MatrixTable.TransformRowsDic() may look like as follows:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // Apply operations on "price" depending on "color"
  2. public static void ApplyPriceOpDic( ref Dictionary TextAttribDic,
  3.     ref Dictionary NumAttribDic, ref Dictionary KeyFigDic)
  4. {
  5.     if (TextAttribDic["color"].ToLower() == "red")
  6.     {
  7.         KeyFigDic["price"] = KeyFigDic["price"] ^ 2;
  8.     }
  9.     else if (TextAttribDic["color"].ToLower() == "blue")
  10.     {
  11.         KeyFigDic["price"] = Math.Sqrt(KeyFigDic["price"]);
  12.     } else {
  13.         // ..
  14.     }
  15.     // round to 2 digits after decimal point
  16.     KeyFigDic["price"] = Math.Round(KeyFigDic["price"], 2);
  17. }
GeSHi ©
Last edited by finaquant on 22 Oct 2013, 09:48, edited 1 time in total.
User avatar
finaquant
 
Posts: 61
Joined: 16 Sep 2013, 18:37

Re: FOX formulas of SAP

Postby finaquant » 22 Oct 2013, 09:47

The row transformation function above might look similar to FOX formulas for SAP users; esp. users of SAP modules related with Business Intelligence.
User avatar
finaquant
 
Posts: 61
Joined: 16 Sep 2013, 18:37

Re: Different operations on numbers depending on attributes

Postby ariston » 23 Oct 2013, 17:51

quite clear, thanks.
ariston
 
Posts: 6
Joined: 20 Oct 2013, 13:51


Return to Table Functions

Who is online

Users browsing this forum: No registered users and 1 guest

cron