# Query Formula Definition

> Source: https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-formula

A *formula* is a PxPlus expression (numeric or string) consisting of any combination of variables, constants and functions, whose resulting value is displayed in a query column. Formulas that have been assigned a name can be used within other formulas, noting that the order of evaluation of formulas corresponds to the order in which they are defined in the query definition.

To invoke the **Query Formula Definition** window, click the *Add Formula* button on the **[Query Definition](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-definition)** toolbar.

![](https://manual.pvxplus.com/migration-assets/7195ca1135c7cd100846944c114667ed5af805d13f7df0c69f1c26e5c2924a75.jpg)

This window consists of the following:

|  |  |
| --- | --- |
| **Formula Name** | ***(Optional)*** Enter a formula name to easily identify the formula throughout the Query Subsystem:<br>• For ***new*** formulas, the formula name will be pre-loaded with **FML\_*QueryName_N*** (where *QueryName* is the name of the query and ***N*** is a numeric identifier), which can be changed or deleted.<br>• For ***existing*** formulas, the formula name will be blank until it is filled in.<br>All formula names will be prefixed with **FML\_** and must adhere to the rules for naming variables. The first character must be alphabetic (A-Z or a-z), the remaining characters can be alphabetic, numeric (0-9), **.** (*period*), or **\_** (*underscore*).<br>Naming a formula allows you to:<br>• Use the evaluated result of the formula in another formula.  <br> • Use the formula as a parameter in a **[Display Option](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-formula#displayoption)**.  <br> • Reference the formula by name in a **[Report Writer](https://manual.pvxplus.com/report-writer/designing-a-report/defining-the-data/input-source#qry_def)** definition.  <br> • Specify a column name for use with the **[\*QUERY\*](https://manual.pvxplus.com/file-handling/query)** interface.<br>Note:  <br>Formula names are *not* backwards compatible.<br>*(Formula Name was added in PxPlus 2020.)* |
| **Column Title** | Column heading that users will see at the top of the formula column at run time; e.g. Customer Name. Can be a *Fixed* value, string *Expression*, or *Message Library Reference*. |
| **Formula** | PxPlus expression (numeric or string) consisting of any combination of variables, constants and functions. In formulas, you can refer to an external key as PRIME_KEY$.<br>***Example:***<br>```<br>CVS(CST_NAME$,256)<br>SURNAME$+","+NAME$(1,1)+","+STR(XXX.FLD#2*100)<br>```<br>See **[Query Variables](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/designing-and-using-the-query-subsystem#queryvariables)**. |
| **Width** | Column width in columns. This can be adjusted as necessary, depending on the selected font.<br>Column widths can also be adjusted in ***Query+*** *Toolbar, Hybrid, Menu* and *Drop Query* views (see **[Query View](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-header#queryview)** option) by clicking the **[Test/Design](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-definition#testdesign)** toolbar button to display the query and dragging the column header to the desired size. Click the *Save + Exit* button to save and incorporate these settings into the query definition when exiting the query.<br>*(The ability to save query changes when in Test/Design mode was added in PxPlus 2023 Update 1.)* |
| **Alignment** | ***(Query+ and Drop Query)***<br>Alignment of the value within the column. Settings include *Default, Left, Center* and *Right* justification. The *Default* setting for ***text*** values is *Left* justification and *Right* justification for ***numeric*** values.<br>Note:  <br>Alignment affects *text displays only* so that just the column title of columns displaying images, percent bars, etc. are affected.<br>*(The Alignment option was added in PxPlus 2018.)* |
| **Format** | Can be either *Mask* or *Program*:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| *Mask* \| PxPlus format mask for the column's data output (fixed value or string expression); e.g. a phone number mask such as 000-000-0000. \|<br>\| *Program* \| Name of the program called to format the display of the string data in this column; e.g. \*win/date;display. On the **ENTER** statement of the sub-program, include one argument (value of the column is passed by your query.) Fixed text or an Expression can define the mask or name the program. \|<br>Note:  <br>To use a Program, the formula must have a [Formula Name](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-formula#formula_name). |
| **Display Option** | Click the *Define* button to launch the **Query Column Display** window where you can assign visual attributes, such as bold text, text color, highlight color, or an image, to the column. See **[Query Column Display](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-definition)** below. |
| **Sort Options** | ***(String Only, Query+, Drop Query and Classic Query with Sort by Column Option)***<br>The following sort options can be assigned to a column: *Sort As Is*, *Use Sort Algorithm*, *Date Sort*:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| *Sort Algorithm* \| ***(Available when Use Sort Algorithm option is selected)***<br>Enter a PxPlus expression to be used as an alternate algorithm for sorting the column.<br>***Example:***<br>A column containing a date stored in a YYYYMMDD format can be displayed as MM/DD/YYYY using the formula DT$(5,4)+DT$(1,2)+DT$(3,2) and a format string such as "XX/XX/XXXX". However, to sort the column chronologically by year, month day, you can use the original value, DT$, as the sort algorithm.<br>Note:  <br>While this would be necessary for proper sorting in a *Classic Query*, *Query+* and *Drop Query* can use the Date Sort to accomplish this as well. \|<br>\| *Sort Key Length* \| ***(Available when Use Sort Algorithm option is selected)***<br>Number of characters to be used to sort the column when using a sort algorithm. Default value is the length of the field to a maximum of 128 characters. \|<br>\| *Date Sort* \| ***(Query+, Drop Query)***<br>***(Available when Date Sort option is selected)***<br>Enter or select a string consisting of D, M and/or Y (day, month, year) to describe the order in which they occur in the data.<br>***Example:***<br>A date in the format MMDDYY would be MDY. \| |
| **'Tip' Values** | ***(Numeric Only, Query+, Drop Query and Classic Query with Sort by Column Option)***<br>***(Optional)*** Tip values to be displayed when the mouse is placed over the column heading. Values include *Total, Average, Minimum* and *Maximum*. |
| **Hotlink Logic** | ***(Query+ and Drop Query)***<br>Logic to execute when the column is double-clicked. Click the drop-down arrow for a list of event actions: *Ignore, Link, Call* and *Execute*. See **[Actions and Parameters](https://manual.pvxplus.com/nomads-graphical-application/program-interaction/events-logic/actions-and-parameters)**.<br>The specified logic overrides selecting the query record. Columns with a hotlink are displayed in the color defined by the **'OPTION'("StdLvueHotlinkClr",color$)** setting and are underlined while hovering over the column. See **[OPTION](https://manual.pvxplus.com/mnemonics/option#hotlinkclr)** mnemonic.<br>\|  \|  \|<br>\| --- \| --- \|<br>\| *Webster Hotlink* \| Specify a hotlink for the column to be used in a **[Webster+](https://manual.pvxplus.com/webster/webster)** environment. Links may specify URLs, pages or events, starting with *http://*, *https://*, *page:* or *event:.* Additional URL parameters can follow the page/program name separated by an **&** *(ampersand)*; e.g. &*fieldname$*=.<br>***Example:***<br>*page*:*pagename*&*fieldname$*=$1<br>The Webster+ hotlink is translated into a Webster+ **[\[link\]](https://manual.pvxplus.com/webster/short-codes#link)** short code:<br>\[link *page*:*pagename*&*fieldname$*=$1\]<br>This results in a hyperlink to the specified page name with *fieldname$* as the variable to be passed to the page/program and $1 being substituted with the value in the column. \|<br>\| *Target* \| ***(Optional)*** Specify a Webster+ target browser window where the results of a link or event will be displayed. Selections are null ***(Default)***, *Same*, *New* or *Popup*.<br>*Same*<br>To have the output replace the current page.<br>*New*<br>To create a new tab/window.<br>*Popup*<br>To create a popup overlaid window. When selected, an input control with a % sign is displayed for entering the percentage of the screen the popup window will occupy. \|<br>*(The Hotlink Logic option was added in PxPlus 2018.)  <br>(The Webster Hotlink option was added in PxPlus 2021 Update 1.)* |
| *Initially Hide Column* | Selecting this check box initially hides the formula column at run time until the user selects it to be shown.<br>When using ***Query+*** *Toolbar, Hybrid, Menu* or *Drop Query* views, columns can be set to be initially hidden or shown by clicking the **[Test/Design](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-definition#testdesign)** toolbar button to display the query and selecting the *Show/Hide/Reorder Columns* item from the **[Columns](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/run-time-query#columns)** run-time option to set the column visibility. Click the *Save + Exit* button to save and incorporate these settings into the query definition when exiting the query.<br>*(The ability to save query changes when in Test/Design mode was added in PxPlus 2023 Update 1.)* |
| *Security* | Launches the **[Object Security Definition](https://manual.pvxplus.com/nomads-graphical-application/system-maintenance-tools/security-manager/restricting-access#objectsecurity)** window for setting up column level security for the query. See **[Query Security](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-security)**.<br>*(The Security button was added in PxPlus 2021.)* |

## See Also

**[Query Definition](https://manual.pvxplus.com/nomads-graphical-application/dictionary-based-development/query-subsystem/query-definition)**
