Difference between revisions of "Expressions"

From TaticView
Jump to: navigation, search
Line 3: Line 3:
  
 
<translate>
 
<translate>
<!--T:1-->
+
You can create expressions (formulas) directly in the dashboard components. It can thus display calculated values that are not present in the data source file/spreadsheet.
Expressions allows to manually create and edit [[Filters]] rules by using programming language.  
 
  
<!--T:2-->
 
'''Important''': After manually editing the expression, the regular operators can not be used until you ''Clear All'' the filters;
 
  
 +
To create the expression (formula) in the components, the component must support the addition of the special column ''Expression (Formula)''.
  
<!--T:3-->
 
__TOC__
 
  
 +
Below are details about how the expressions work:
  
== Basic Expression Structures == <!--T:4-->
+
=== Basic structure of a Expression (Formula) ===
  
  
=== Value Operands === <!--T:5-->
+
==== Value Operand ====
  
<!--T:6-->
+
It's the numerical values. You can use both while values and decimal values. For decimal values, the decimal separator should be the point.
The value operands are values from a [[Columns Data Type|data type]] that are used in expressions as variables.
 
  
 +
* Examples: 1, 1.05, 2.55
  
==== Value type operand ==== <!--T:7-->
 
Are numeric values of the float type (Real numbers domain). These values allow the use of an integer and a fraction part, separated by the dot (.) character (decimal separator).
 
  '''Examples''': 1, 1.05, 2.55;
 
  
==== Text type operand ==== <!--T:8-->
+
==== Text Operand ====
Are literal string data operands. These values allow the use of characters chain fields (strings), being delimited by the simple quote (') character.
 
  '''Examples''': 'John Snow', 'California', 'Spaghetti';
 
  
==== Date type operand ==== <!--T:9-->
+
It's the text operands. If you want to use this type of operand in a expression, you must delimit them by the single quotation mark (').
Are values that express any date. It is possible to determine a date representing it as a string, being delimited by the simple quote (') character and separated by the bar (/) character. The default supported format is "dd/MM/yyyy".
 
  '''Examples''': '01/01/2011', '29/02/2000';
 
  
==== Boolean type operand ==== <!--T:10-->
+
* Examples: 'John Snow', 'California', 'Spaghetti'
Are values from the ''true'' or ''false'' kind. Usually used to validate or not a condition.
 
  '''Examples''': true e false;
 
  
==== Identifier type operand ==== <!--T:11-->
 
Are values that represent a field or variable in the expression. Used to make reference to data source columns, delimited by double quotes (").
 
  '''Examples''': "City.City", "Product.Product";
 
  
==== Parenthesis ==== <!--T:12-->
+
==== Date Operand ====
Used to group and separate expressions parts. Expressions inside parenthesis are processed first.
 
  '''Examples''': ("Profit" / "Total Price" ) + 10
 
  
==== System variable type operand ==== <!--T:13-->
+
These are values that express any date. To represent a date in expressions the behaviour is similar to text operands, i.e. the content must be surrounded by single quotation marks ('). However, the mask ''dd/MM/yyyy'' must be used.
Are system pre-defined variables. These values are replaced in run-time by pre-determined values, delimited by double quotes (") and preceded by star (#). By now only one variable is available: "#null" that indicates null values or fields.
 
  
 +
* Examples: '01/01/2019', '14/11/2019', '25/12/2019'
  
=== Arithmetic Expressions === <!--T:14-->
 
  
<!--T:15-->
+
==== Boolean Operand ====
The arithmetic expressions relate two operands (value or another expression) to compose a sum, subtraction, multiplication or division.
 
  
==== Sum (+) ==== <!--T:16-->
+
They're operators of the true or false type. Normally user to validate, or not, a condition in a more complex expression.
Sum two operands. Represented by the sum (+) character.  
 
    Syntax: ''<operand/expression> + <operand/expression>''.  
 
  '''Examples''': "Taxes" + "Commissions";
 
  
==== Subtraction (-) ==== <!--T:17-->
+
* Examples: true, false
Subtract two operands. Represented by the subtract or hyphen (-) character.
 
    Syntax: ''<operand/expression> - <operand/expression>''.
 
  '''Examples''': "Gross Sale" - "Taxes";
 
  
==== Multiplication (*) ==== <!--T:18-->
 
Multiplicate two operands. Represented by the multiplication or star (*) character.
 
    Syntax: ''<operand/expression> * <operand/expression>''.
 
  '''Examples''': "Amount" * "Unit Price";
 
  
==== Division(/) ==== <!--T:19-->
+
==== Parentheses ====
Divides two operands. Represented by the divide or bar (/) character.
 
    Syntax: ''<operand/expression> / <operand/expression>''.
 
  '''Examples''': "Total Value" / "Amount".
 
  
 +
Used to group and separate parts of on expression. Expressions within parentheses are processed first.
  
=== Relational Expressions === <!--T:20-->
+
* Example: ("Profit"/"Total Price") + 10
  
<!--T:21-->
 
The relational expressions compare two operands (value or another expression) to evaluate if a condition is ''true'' or ''false''. Usually used with decision functions, like the ''IF''.
 
  
==== Equal (==) ==== <!--T:22-->
+
==== System variable Operand ====
Performs the equal comparison expression between two operands. Represented by the equal operator (==).
 
    Syntax: ''<expression> == <expression>''.
 
  '''Examples''': "Unit Price" == "Total Price";
 
  
==== Different (!=) ==== <!--T:23-->
+
These are predefined variables in the system. To use the system variables you must precede them by hashtag (#) and delimit them by double quotes("). Currently only the "#null" variable is available and indicates null content.
Performs the different comparison expression between two operands. Represented by the different operator (!=).  
 
    Syntax: ''<expression> != <expression>''.
 
  '''Examples''': "City.City" != 'New York';
 
  
==== Greater than (>) ==== <!--T:24-->
+
* Example: IF("Product" == "#null";0;20)
Return ''true'' if the first expression is greater than the second expression and ''false'' otherwise. Represented by the greater operator (>).
 
    Syntax: ''<expression> > <expression>''.
 
  '''Examples''': "Order Date" > '01/01/2011';
 
  
==== Greater or equal than (>=) ==== <!--T:25-->
 
Return ''true'' if the first expression is greater than or equal to the second expression and ''false'' otherwise. Represented by the greater or equal operator (>=).
 
    Syntax: ''<expression> >= <expression>''.
 
  '''Examples''': IF("Order Date" >= '01/01/2011';"Order Date";0);
 
  
==== Lesser than (<) ==== <!--T:26-->
+
=== Arithmetic Expressions ===
Return ''true'' if the first expression is lesser than the second expression and ''false'' otherwise. Represented by the lesser operator (<).
 
    Syntax: ''<expression> < <expression>''.
 
  '''Examples''': "Profit" < '0';
 
  
==== Lesser or equal than (<=) ==== <!--T:27-->
+
Arithmetic expressions relate two operands (which can be any the operands described above, or another expression) to make up the sum, subtraction, multiplication or division.
Return ''true'' if the first expression is lesser than or equal to the second expression and ''false'' otherwise. Represented by the lesser or equal operator (<=).
 
    Syntax: ''<expression> <= <expression>''.
 
  '''Examples''': IF("Order Date" <= '01/01/2011';"Order Date";0).
 
  
  
=== Logical Expressions === <!--T:28-->
+
==== Sum (+) ====
  
<!--T:29-->
+
Add two value operands or another expression result. Represented by the ''+'' charecter.
The logical expressions group two operands (boolean type or another expression) to compose a logic expression, with the objective to evaluate two boolean operands relation into a ''true'' or ''false'' result. Usually used with decision functions, like the ''IF'', and with relational expressions.
 
  
 +
Syntax:
 +
  <operating or expression result> '''+''' <operating or expression result>
 +
Example:
 +
  "Taxes" + "Commissions"
  
==== And (&&) ==== <!--T:30-->
 
Performs the logical operation ''AND'' between two boolean values. The two operands must be ''true'' for the result of the operation to be ''true''. Represented by the ''AND'' operator (&&).
 
    Syntax: ''<expression> && <expression>''.
 
  '''Examples''': IF((Gross Sales > '0') && (Seller == 'John Snow');'Sold';'Not Sold'), IF((City!="#null") && (Date<DAY_FROM_TODAY(0));1;0);
 
  
==== Or (||) ==== <!--T:31-->
+
==== Subtraction (-) ====
Performs the logical operation ''OR'' between two boolean values. One of the two operands must be ''true'' for the result of the operation to be ''true''. Represented by the ''OR'' operator (||).
 
    Syntax: ''<expression> || <expression>''.
 
  '''Examples''': IF((Gross Sales > '0') || (Sold == 'true');'Sold';'Not Sold'), IF((City!="#null") || (Date<DAY_FROM_TODAY(0));1;0);
 
  
==== Not (!) ==== <!--T:32-->
+
Subtract two value operands or another expression result. Represented by the ''-'' charecter.
Performs the denial logical operation for a boolean value. If the operand is ''true'' the ''NOT'' convert it to ''false'' (and the other way around). Represented by the ''NOT'' operator (!).
 
    Syntax: ''! <expression>''.
 
  '''Examples''': IF(!BETWEEN("Date", '01/01/2013', '31/12/2013');'Not 2013';'2013').
 
  
 +
Syntax:
 +
  <operating or expression result> '''-''' <operating or expression result>
 +
Example:
 +
  "Price" - "Taxes"
  
== Auxiliary Functions == <!--T:33-->
 
  
=== Basic Functions === <!--T:34-->
+
==== Multiplication (*0 ====
  
<!--T:35-->
+
Multiplies two value operands or another expression result. Represented by the multiplication charecter ''*''.
The basic functions are system default functions and implements useful functionalities.
 
  
==== Abs ==== <!--T:36-->
+
Syntax:
Returns the absolute value of a base value.
+
  <operating or expression result> '''*''' <operating or expression result>
    Syntax: ''ABS(<expression>)''. Accept one parameter and process a numeric data type.
+
Example:
  '''Examples''': ABS(Gross Sale-Taxes);
+
  "Quantity" * "Unit Price"
  
==== Avg ==== <!--T:37-->
 
Returns the average value of an array of values.
 
    Syntax: ''AVG(<expression1>;<expression2>[;<expression3>;...;<expressionN>])''. Accept multiple parameter and process a numeric data type.
 
            Can be used to return the average value of different columns from the same row of a table.
 
  '''Examples''': AVG(Taxes;Commissions;Costs);
 
  
==== Between ==== <!--T:38-->
+
==== Division (/) ====
Check if a value is within the boundaries of the parameters values.
 
    Syntax: ''BETWEEN(<expression_to_test>;<expression_bottom_limit>;<expression_top_limit>)''. Need three parameters (of any data type, but
 
            the three must be from the same type) and returns a boolean, ''true'' if value is inside the boundaries and ''false'' if not.
 
  '''Examples''': BETWEEN("Date";'01/01/2013';'31/12/2013'), BETWEEN("Gross Sales";'0';'1000.00');
 
  
==== If then else ==== <!--T:39-->
+
Divide two value operands or another expression result. Represented by the division charecter ''/''.
Tests a boolean expression and returns a value in case it is ''true'' and another in case it is ''false''.  
 
    Syntax: ''IF(<expression_test>;<expression_for_true>;<expression_for_false>)''. Need three parameters, a boolean for test and returns any
 
            data type, provided that both are from the same type. Useful for logic tests where two different executions expressions are
 
            needed.
 
  '''Examples''': IF("Branch"=='SOUTH';'South';'Other Branch')
 
            IF("Profit"==0;0;Profit+Taxes);
 
  
==== Log ==== <!--T:40-->
+
Syntax:
Returns the log value of a number on a set base.
+
  <operating or expression result> '''/''' <operating or expression result>
    Syntax: ''LOG(<expression_number>[;<expression_base>])''. Minimum one parameter and maximum two. If just one parameters is given, the
+
Example:
            neperian log is returned. If the second parameter is also given, returns the log in the respective base.
+
  "Price" / "Quantity"
  '''Examples''': LOG(Profit);
 
  
==== Max ==== <!--T:41-->
 
Returns the greater value between two numbers.
 
    Syntax: ''MAX(<expression_value1>;<expression_value2>)''. Need two value parameters and returns a value data type.
 
  '''Examples''': "Total Value"/MAX("Quantity";"1");
 
  
==== Min ==== <!--T:42-->
+
=== Relational Expressions ===
Returns the smaller value between two numbers.
 
    Syntax: ''MIN(<expression_value1>;<expression_value2>)''. Need two value parameters and returns a value data type.
 
  '''Examples''': "Total Value"/MIN("Quantity";"1");
 
  
==== Pow ==== <!--T:43-->
+
Relational expressions compare two operands (value/text or other expression) to assess whether a condition is true or false. Normally used with decision functions, such as ''IF''.
Returns the power value of a number on a set exponent.  
 
    Syntax: ''POW(<expression_number>[;<expression_exponent>])''. Minimum one parameter and maximum two. If the exponent value is not given,
 
            use two (2) by default.
 
  '''Examples''': POW(Value1)+POW(Value1-Value2;3);
 
  
==== Random ==== <!--T:44-->
 
Returns an aleatory number inside the boundaries of the limit values.
 
    Syntax: ''RANDOM(<expression_bottom_limit>;<expression_top_limit>)''. Need two parameters, the bottom and the upper limit of the random
 
            number to be generated.
 
  '''Examples''': RANDOM(0.0;1.0);
 
  
==== Sqrt ==== <!--T:45-->
+
==== Equality (==) ====
Returns the square root of a value.
 
    Syntax: ''SQRT(<expression>)''. Need one parameters, the value to be calculated.
 
  '''Examples''': SQRT('36').
 
  
==== Like ==== <!--T:67-->
+
It compares if two operands are the same, returning true if they are the same or false if they are different. Represented by the equality operator ''==''.
Returns true if the desired content is found in the list and false if the content is not found.
 
    Syntax: ''LIKE(<data_set>;<pattern>)''. Needs two parameters, the first is the set of data that will be queried. The second is the term one wishes to find, in the data set. Returns true or false.
 
  '''Examples''': LIKE("Product";'%ghe%'). Returns true if in the ''Product'' dataset there is some containing ''gue''. Otherwise, returns false.
 
  
=== Date Functions === <!--T:46-->
+
Syntax:
 +
  <operating or expression result> '''==''' <operating or expression result>
 +
Example:
 +
  IF("Product" == "#null";0;20)
  
<!--T:47-->
 
The date functions are operations that use as parameters and return the result of the [[Date|date data type]].
 
 
==== Constants list ==== <!--T:48-->
 
** '''0''': DATE_FIELD_YEAR (Year part);
 
** '''1''': DATE_FIELD_MONTH (Month part);
 
** '''2''': DATE_FIELD_DAY (Day part);
 
** '''3''': DATE_FIELD_FORTNIGHT (Fortnight part);
 
** '''5''': DATE_FIELD_WEEK (Week part);
 
 
 
==== Date part ==== <!--T:49-->
 
Return a part of a date.
 
    Syntax: ''DATE_PART(<expression_date>;<constant>)''. Need two parameters, the first is the reference date and the second the constant
 
            representing the desired part date: 0, 1, 2, 3 or 5 (see above constants list).
 
  '''Examples''': DATE_PART("Order Date";0) - returns the year part of the "Order Date";
 
 
==== Day from today ==== <!--T:50-->
 
Return a backward (negative) or forward (positive) date counting from today.
 
    Syntax: ''DAY_FROM_TODAY(<expression_number_days>)''. Need one parameter, the number of days to add or subtract.
 
  '''Examples''': DAY_FROM_TODAY(-1) - returns the yesterday date;
 
 
==== First day of ==== <!--T:51-->
 
Return the first day of a grouping. This function has two variations:
 
* '''First way''':
 
    Syntax: ''FIRST_DAY_OF(<constant_grouping>;<expression_date>)''. Need two parameters, the first is the constant grouping in which you
 
            want to obtain the first date: 0, 1, 2, 3 or 5 (see constants list) and the second is the anchor base date.
 
  '''Examples''': FIRST_DAY_OF(0;DAY_FROM_TODAY(0)) - first day of year (0) from today (DAY_FROM_TODAY(0)), FIRST_DAY_OF(1;"Order Date") -
 
            first day of month (1) based on the "Order Data";
 
* '''Second way''':
 
    Syntax: ''FIRST_DAY_OF(<constant_grouping>;<constant_modify_date>;<modify_date_value>)''. Need three parameters, the first is the
 
            constant grouping in which you want to obtain the first date: 0, 1, 2, 3 or 5 (see constants list), the second is the modifier
 
            of the base date from today: 0, 1, 2, 3 or 5 (see constants list) and the third is the amount to change the modifier.
 
  '''Examples''': FIRST_DAY_OF(1;0;-1) - first day of the current month (1) from last year (0;-1);
 
 
==== Last day of ==== <!--T:52-->
 
Return the last day of a grouping. This function has two variations:
 
* '''First way''':
 
    Syntax: ''LAST_DAY_OF(<constant_grouping>;<expression_date>)''. Need two parameters, the first is the constant grouping in which you
 
            want to obtain the last date: 0, 1, 2, 3 or 5 (see constants list) and the second is the anchor base date.
 
  '''Examples''': LAST_DAY_OF(0;DAY_FROM_TODAY(0)) - last day of year (0) from today (DAY_FROM_TODAY(0)), LAST_DAY_OF(1;"Order Date") -
 
            last day of month (1) based on the "Order Data";
 
* '''Second way''':
 
    Syntax: ''LAST_DAY_OF(<constant_grouping>;<constant_modify_date>;<modify_date_value>)''. Need three parameters, the first is the
 
            constant grouping in which you want to obtain the last date: 0, 1, 2, 3 or 5 (see constants list), the second is the modifier
 
            of the base date from today: 0, 1, 2, 3 or 5 (see constants list) and the third is the amount to change the modifier.
 
  '''Examples''': LAST_DAY_OF(1;0;-1) - last day of the current month (1) from last year (0;-1);
 
 
==== New date ==== <!--T:53-->
 
Create an object from a day, month and year.
 
    Syntax: ''NEW_DATE(<expression_day>;<expression_month>;<expression_year>)''. Need three parameters, the first is a valid day number (1 to
 
            31), the second for a month (1 to 12) and the third is a year. The date is created from year to day, therefore, the day must be
 
            valid for the month and the year (considering 29/02, year must be bissextile).
 
  '''Examples''': NEW_DATE(1;4;DATE_PART("Order Date";0)) - create the first day of april from the year determined by the current row
 
            "Order Date" column;
 
 
==== Num of days ==== <!--T:54-->
 
Return the number of days between two dates.
 
    Syntax: ''NUM_OF_DAYS(<expression_date1>;<expression_date2>)''. Need two date data type parameters.
 
  '''Examples''': NUM_OF_DAYS(FIRST_DAY_OF(0;"Order Date");"Order Date") - returns the number of days between the first day of year based on
 
            the "Order Date" column to the current day of the "Order Date" column,
 
            NUM_OF_DAYS(FIRST_DAY_OF(1;"Pay Date"); LAST_DAY_OF(1;"Pay Date")) - returns the number of days of the month of the "Pay Date"
 
            column;
 
 
==== Num of months ==== <!--T:55-->
 
Return the number of months between two dates.
 
    Syntax: ''NUM_OF_MONTHS(<expression_date1>;<expression_date2>)''. Need two date data type parameters.
 
  '''Examples''': NUM_OF_MONTHS(FIRST_DAY_OF(0;"Date");"Date") - Return the number of months between the first day of the year of the "Date"
 
            column and the current month of the "Date" column;
 
 
==== Previous date ==== <!--T:56-->
 
Return the closest exact previous date given a day and month.
 
    Syntax: ''PREVIOUS_DATE(<expression_day>;<expression_month>)''. Need two parameters, the first is the day of month and the second the
 
            month.
 
  '''Examples''': PREVIOUS_DATE(1;4) - return the closest ''01/04'', in other words, until "01/04/current year", returns "01/04/last year",
 
            after that returns "01/04/current year".
 
 
 
==== Special variables ==== <!--T:57-->
 
 
<!--T:58-->
 
Special variables can be used with the expressions.
 
 
<!--T:66-->
 
'''Important:''' The variables below must be enclosed in double quotation marks
 
 
<!--T:59-->
 
    "@count" - Total number of lines returned in a table.
 
 
<!--T:60-->
 
    "@row" - current line number.
 
 
<!--T:61-->
 
    "@sum[Column]" - Sum of indicated column.
 
 
<!--T:63-->
 
    "@avg[Column]" - Avg of indicated column like @sum[Column] / @count
 
 
<!--T:64-->
 
    "@prev[column]" - Previous row column value
 
 
<!--T:65-->
 
    "@accumCol[column]" - Current accumulated column value. Useful to calculate Variable Avg ("@accumCol[column]" / "@row")
 
  
  
 
</translate>
 
</translate>

Revision as of 18:10, 20 November 2019

Other languages:
English • ‎português do Brasil


You can create expressions (formulas) directly in the dashboard components. It can thus display calculated values that are not present in the data source file/spreadsheet.


To create the expression (formula) in the components, the component must support the addition of the special column Expression (Formula).


Below are details about how the expressions work:

Basic structure of a Expression (Formula)

Value Operand

It's the numerical values. You can use both while values and decimal values. For decimal values, the decimal separator should be the point.

  • Examples: 1, 1.05, 2.55


Text Operand

It's the text operands. If you want to use this type of operand in a expression, you must delimit them by the single quotation mark (').

  • Examples: 'John Snow', 'California', 'Spaghetti'


Date Operand

These are values that express any date. To represent a date in expressions the behaviour is similar to text operands, i.e. the content must be surrounded by single quotation marks ('). However, the mask dd/MM/yyyy must be used.

  • Examples: '01/01/2019', '14/11/2019', '25/12/2019'


Boolean Operand

They're operators of the true or false type. Normally user to validate, or not, a condition in a more complex expression.

  • Examples: true, false


Parentheses

Used to group and separate parts of on expression. Expressions within parentheses are processed first.

  • Example: ("Profit"/"Total Price") + 10


System variable Operand

These are predefined variables in the system. To use the system variables you must precede them by hashtag (#) and delimit them by double quotes("). Currently only the "#null" variable is available and indicates null content.

  • Example: IF("Product" == "#null";0;20)


Arithmetic Expressions

Arithmetic expressions relate two operands (which can be any the operands described above, or another expression) to make up the sum, subtraction, multiplication or division.


Sum (+)

Add two value operands or another expression result. Represented by the + charecter.

Syntax:

 <operating or expression result> + <operating or expression result>

Example:

 "Taxes" + "Commissions"


Subtraction (-)

Subtract two value operands or another expression result. Represented by the - charecter.

Syntax:

 <operating or expression result> - <operating or expression result>

Example:

 "Price" - "Taxes"


Multiplication (*0

Multiplies two value operands or another expression result. Represented by the multiplication charecter *.

Syntax:

 <operating or expression result> * <operating or expression result> 

Example:

 "Quantity" * "Unit Price"


Division (/)

Divide two value operands or another expression result. Represented by the division charecter /.

Syntax:

 <operating or expression result> / <operating or expression result>

Example:

 "Price" / "Quantity"


Relational Expressions

Relational expressions compare two operands (value/text or other expression) to assess whether a condition is true or false. Normally used with decision functions, such as IF.


Equality (==)

It compares if two operands are the same, returning true if they are the same or false if they are different. Represented by the equality operator ==.

Syntax:

 <operating or expression result> == <operating or expression result>

Example:

 IF("Product" == "#null";0;20)