Converting Formulas

Converting Formulas

Developers can return Microsoft Excel formulas from views, stored procedures, and SQL queries.

For example:

SELECT
    id,
    name,
    qty,
    price,
    '=@qty*@price' AS amount
...

SaveToDB products convert these formulas into platform-specific calculated formulas (Excel, DataTable, or JavaScript).

The SaveToDB add-in supports all Excel formulas, while DBEdit, DBGate, and ODataDB support a subset.

SaveToDB products detect formulas by examining the first-row cell, analyzing the column formulas, and applying the formula to the entire column or each cell.

ConvertFormulas and DoNotConvertFormulas

Developers can enable or disable formula conversion using the ConvertFormulas and DoNotConvertFormulas handlers in the xls.handlers table.

For example:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s02usp_cashbook5balanceConvertFormulasATTRIBUTE
 xlshandlersHANDLER_CODEDoNotConvertFormulasATTRIBUTE

Use ConvertFormulas to enforce formula conversion even if the first-row cell doesn't contain a formula, such as an initial balance.

Use DoNotConvertFormulas to prevent conversion when the first-row cell might contain a value, like in the HANDLER_CODE field.

Formula and FormulaValue

Developers can set formulas to calculate column values using the Formula event type and specifying formulas in the HANDLER_CODE field.

For example:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s04usp_order_formamountFormulaATTRIBUTE=@qty*@price
 s22cashbookamountDoNotChangeATTRIBUTE

This case is similar to the one shown in the introduction. The query returns actual data, not formulas, while the formulas are added after loading. This method can also be used for tables.

Additionally, products save all rows when new calculated values differ from the loaded values. This feature allows for recalculating column values.

The sample configuration also includes the DoNotChange handler, which disables manual cell changes.

The second option is FormulaValue.

For example:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s22cashbookmodified_byFormulaValueATTRIBUTE=DomainUserName()
 s22cashbookmodified_onFormulaValueATTRIBUTE=NOW()
 s22cashbookmodified_byDoNotChangeATTRIBUTE
 s22cashbookmodified_onDoNotChangeATTRIBUTE

Unlike the Formula type, these formulas are calculated when a user modifies any row cell.

You can use standard Excel formulas or special built-in formulas like =DomainUserName() and =UserName().

Using DDE Formulas

You can use the SaveToDB add-in to easily create DDE dashboards.

For example, here’s a sample SQLite configuration for a Thinkorswim watch list using an SQL query in the xls.objects table:

IDTABLE_SCHEMATABLE_NAMETABLE_TYPETABLE_CODEINSERT_OBJECTUPDATE_OBJECTDELETE_OBJECT
 DDE WatchListCODE<SQL code>WatchListWatchListWatchList

In the TABLE_CODE field, include the following SQL code:

SELECT
    Symbol,
    '=TOS|LAST!' + Symbol AS Last,
    '=TOS|NET_CHANGE!' + Symbol AS NetChange,
    '=TOS|PERCENT_CHANGE!' + Symbol AS Change,
    '=TOS|HIGH!' + Symbol AS High,
    '=TOS|LOW!' + Symbol AS Low,
    '=SUBSTITUTE(TOS|VOLUME!' + Symbol + '," ","")+0' AS Volume
FROM
    WatchList

Note that you can save data to SQLite databases using the free SaveToDB edition.

This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.