Difference between revisions of "Expressions/pt-br"

From TaticView
Jump to: navigation, search
(Created page with "Sintaxe: <expressão> && <expressão> Exemplos: '''IF(("Preço" > 0) && ("Vendedor" == 'André Moraes');450;0)''' – Se o ''Preço'' for maior que ''0'' '''E''' o ''Vend...")
Line 197: Line 197:
 
Exemplos:
 
Exemplos:
 
   '''IF(("Preço" > 0) && ("Vendedor" == 'André Moraes');450;0)''' – Se o ''Preço'' for maior que ''0'' '''E''' o ''Vendedor'' for igual a ''André Moraes'', retorna ''450'', se não retorna ''0''
 
   '''IF(("Preço" > 0) && ("Vendedor" == 'André Moraes');450;0)''' – Se o ''Preço'' for maior que ''0'' '''E''' o ''Vendedor'' for igual a ''André Moraes'', retorna ''450'', se não retorna ''0''
 
  
 
'''IF(("Cidade" != "#null") && ("Produto" != 'Lasanha');1;0) – Se a ''Cidade'' for diferente de nula '''E''' o ''Produto'' for diferente de ''Lasanha'' retorna ''1'', se não retorna ''0''
 
'''IF(("Cidade" != "#null") && ("Produto" != 'Lasanha');1;0) – Se a ''Cidade'' for diferente de nula '''E''' o ''Produto'' for diferente de ''Lasanha'' retorna ''1'', se não retorna ''0''

Revision as of 19:36, 22 November 2019

Other languages:
English • ‎português do Brasil


É possível criar expressões (fórmulas) diretamente nos componentes dos painéis. Podendo assim exibir valores calculados que não estão presentes no arquivo/planilha de origem dos dados.


Para criar as expressões (fórmulas) nos componentes, é necessário que o componente suporte à adição da coluna especial Expressão (Fórmula).


No TaticView, é possível utilizar nas expressões todas as colunas existentes no arquivo de dados, desde que estes sejam adicionados ao componente que receberá a expressão.


Além disso, também é possível utilizar números e textos fixos nos casos de expressões comparativas e ou cálculos matemáticos.


Exemplo de expressão:

  • Se o componente possui as colunas Preço Total e Quantidade, pode-se criar uma expressão para calcular o Preço Unitário. Ficaria assim:
    • Preço Total / Quantidade
  • Além disso, pode-se utilizar valores fixos, como por exemplo:
    • Preço Total / 10


Lembramos apenas que atualmente o TaticView suporta apenas expressões cujo retorno é numérico.


Abaixo detalhes sobre o funcionamento das expressões.

Estrutura básica de uma expressão

Operando de Valor

São os valores numéricos. É possível utilizar tanto valores inteiros quanto valores decimais. Para valores decimais, o separador decimal deverá ser o ponto.

  • Exemplos: 1, 1.05, 2.55


Operando de Texto

São os operandos de texto. Para utilizar esse tipo de operando em uma expressão é necessário delimita-los pelo caractere aspa simples (').

  • Exemplos: 'André Moraes', 'São Paulo', 'Espaguete'


Operando de Data

São valores que expressam qualquer data. Para representar uma data nas expressões o comportamento é semelhante aos operandos de texto, ou seja, o conteúdo deve ser circundado por aspa simples ('). Porém deve-se utilizar a máscara dd/MM/aaaa.

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


Operando Booleano

São operadores do tipo verdadeiro ou falso. Normalmente utilizados para validar, ou não, uma condição em uma expressão mais complexa.

  • Exemplos: true, false


Parênteses

Utilizados para agrupar e separar partes de uma expressão. Expressões dentro de parênteses são processados antes das demais.

  • Exemplos: ("Lucro"/"Preço Total") + 10


Operando de variável do sistema

São variáveis pré-definidas no sistema. Para utilizar as variáveis do sistema deve-se precede-las por hashtag (#) e delimita-las por aspas duplas ("). Atualmente apenas a variável "#null" está disponível e indica conteúdos nulos.

  • Exemplo: IF("Produto" == "#null";0;20)


Expressões Aritméticas

As expressões aritméticas relacionam dois operandos (que pode ser qualquer um dos operandos descritos acima, ou ainda outra expressão) para compor a soma, subtração, multiplicação ou divisão.


Soma (+)

Soma dois operandos de valor. Representado pelo caractere +.

Sintaxe:

 <operando ou expressão> + <operando ou expressão>

Exemplo:

 "Impostos" + "Comissões" – Soma os valores dos campos Impostos e Comissões


Subtração (-)

Subtrai dois operandos de valor ou o resultado de outra expressão. Representado pelo caractere -.

Sintaxe:

 <operando ou expressão> - <operando ou expressão>

Exemplo:

 "Preço" – "Impostos" – Subtrai os valores dos campos Preço e Impostos


Multiplicação (*)

Multiplica dois operandos de valor ou resultados de outra expressão. Representado pelo caractere de multiplicação *.

Sintaxe:

 <operando ou expressão> * <operando ou expressão>

Exemplo:

 "Quantidade" * "Preço Unitário" – Multiplica o valor do campo Quantidade pelo valor do campo Preço Unitário


Divisão (/)

Divide dois operandos de valor ou resultado de outras expressões. Representada pelo caractere de divisão /.

Sintaxe:

 <operando ou expressão> / <operando ou expressão>

Exemplo:

 "Preço" / "Quantidade" – Divide o valor do campo Preço pelo valor do campo Quantidade


Expressões Relacionais

As expressões relacionais comparam dois operandos (valor/texto ou outra expressão) para avaliar se uma condição é verdadeira (true) ou falsa (false). Normalmente utilizada com funções de decisão, como o IF (Se).


Igualdade (==)

Compara se dois operandos são iguais, retornando true se forem iguais ou false se diferentes. Representado pelo operador de igualdade ==.

Sintaxe:

 <operando ou expressão> == <operando ou expressão>

Exemplo:

 IF("Produto" == "#null";0;20) – Se o produto for nulo, considera o valor 0. Caso contrário considera o valor 20


Diferente (!=)

Compara se dois operandos são diferentes, retornando true se foram diferentes ou false se iguais. Representado pelo operador de diferença !=.

Sintaxe:

 <operando ou expressão> != <operando ou expressão>

Exemplo:

 IF("Produto" != 'LASANHA';0;20) – Se o produto for diferente de Lasanha, considera o valor 0. Caso contrário considera o valor 20


Maior que (>)

Compara se o primeiro operador (da esquerda) é maior que o segundo operador (da direita), retornando true se for maior e false se for menor ou igual. Representado pelo operador maior >.

Sintaxe:

 <operando ou expressão> > <operando ou expressão>

Exemplo:

 IF("Valor Bruto" > 1000;1;0) – Se o Valor Bruto for maior que 1000, retorna o valor 1, se não o valor 0


Maior ou igual a (>=)

Compara se o primeiro operador (da esquerda) é maior ou igual ao segundo operador (da direita), retornando true se for maior ou igual e false se for menor. Representado pelo operador maior >=.

Sintaxe:

 <operando ou expressão> >= <operando ou expressão>

Exemplo:

 IF("Valor Bruto" >= 2500;100;0) – Se o Valor Bruto for maior ou igual a 2500 retorna 100, caso contrário retorna 0


Menor que (<)

Compara se o primeiro operador (da esquerda) é menor que o segundo operador (da direita), retornando true se for menor e false se for maior ou igual. Representado pelo operador maior <.

Sintaxe:

 <operando ou expressão> < <operando ou expressão>

Exemplo:

 IF("Valor Bruto" < 100;50;200) – Se o Valor Bruto for menor que 100, retorna 50, se não retorna 200


Menor ou igual a (<=)

Compara se o primeiro operador (da esquerda) é menor ou igual ao segundo operador (da direita), retornando true se for menor ou igual e false se for maior. Representado pelo operador maior <=.

Sintaxe:

 <operando ou expressão> <= <operando ou expressão>

Exemplo:

 IF("Valor Bruto" <= 500;100;0) – Se o Valor Bruto for menor ou igual a 500 retorna 100, se não retorna 0


Expressões Lógicas

As expressões lógicas agrupam dois operandos (booleano ou outra expressão) para compor uma expressão lógica, com o objetivo de avaliar a relação de dois operadores booleanos em um resultado verdadeiro (true) ou falso (false). Normalmente esse tipo de expressão é utilizada para tomadas de decisão, como o IF (Se) e com expressões relacionais.


And Operator (&&)

Executes the logical operation AND between two Boolean values. Both values must return true so that the result of the operation is true. Represented by the && operator.

Sintaxe:

 <expressão> && <expressão>

Exemplos:

 IF(("Preço" > 0) && ("Vendedor" == 'André Moraes');450;0) – Se o Preço for maior que 0 E o Vendedor for igual a André Moraes, retorna 450, se não retorna 0

IF(("Cidade" != "#null") && ("Produto" != 'Lasanha');1;0) – Se a Cidade for diferente de nula E o Produto for diferente de Lasanha retorna 1, se não retorna 0


Or Operator (||)

Performs the logical OR operation between two Boolean values. A two values must be true so that the result of the operation is true. Represented by the operator ||.

Syntax:

 <expression> || <expression>

Examples:

 IF(("Price" > 1000) || ("Profit" >= 50);75;55) - If Price is greater than 1000 OR Profit is greater than or equal to 50 returns 75 if not 55
 IF(("City" != "#null") || ("Product" != 'Lasagna');1;0) - If City is non-null OR Product is different from Lasagna returns 1 if it does not return 0


Denial Operator (!)

Performs the logical negation operation for a boolean value. If the result of the operation is true the negation operator converts to false and vice versa. Represented by the operator !.

Syntax:

 !<expression>

Example:

 IF(!BETWEEN("Delivery Date"; '01/01/2015'; '31/12/2015');2016;2015) - If the Delivery Date is NOT between 01/01/2015 and 12/31/2015 returns 2016. If between this period returns 2015


Auxiliary Functions

Basic helper functions are standard system functions and implement useful features for composing complex expressions.


ABS function

Function that returns the absolute numeric value of a base numeric value.

Syntax:

 ABS(<value operator or expression>)

Example:

 ABS("Price" / "Quantity") - Returns the absolute value of Price divided by Quantity


AVG function

Returns the average of the values ​​of a sequence of values. It can be used to return the average of different values ​​of the same row of tables.

Syntax:

 AVG(<expression 1>; <expression 2>; ...)

Example:

 AVG("Taxes"; "Profit"; "Cost") - Returns the average between the sum of the Taxes, Profit and Cost columns


BETWEEN function

Checks whether a value is within the limits of the parameters used. Return true or false.

Syntax:

 BETWEEN(<expression to be tested>; <initial limit>; <end limit>)

Example:

 BETWEEN("Date Issued"; '01/01/2019'; '31/12/2019') - Returns true if Date Issued is between 01/01/2019 and 12/31/2019. Otherwise returns false


IF ELSE function (If .... Otherwise ...)

Tests a Boolean expression and applies a condition to true or another condition to false. You need three parameters, separated by semicolons (;). The first parameter is the expression to be tested, the second the value to be applied in case of true, and the third to be applied in case of false.

Syntax:

  IF(<expression to be tested>; <expression if true>; <expression if false>)

Examples:

 IF(BETWEEN("Value";0;100);10;250) - If Value is between 0 and 100 returns 10, if not 250
 IF("Profit" == 0;0;"Profit" + "Taxes") - If Profit equals 0 returns 0, if it does not return the sum between Profit and Taxes


LOG function

Returns the logarithm of a number on a defined basis. It can be used with only one parameter, in this case the neperian (natural) logarithm is used . If two parameters are used, the second server to inform the base to be used by the logarithm.

Syntax:

 LOG(<expression>;<base>)

Examples:

 LOG("Profit")- Returns the logarithm of the field Profit
 LOG("Price";2) - Returns the logarithm of the Price field in base 2


MAX function

Returns the largest value between two values.

Syntax:

  MAX(<expression 1>;<expression 2>)

Example:

 "Value" / MAX("Quantity";1) - Divides Value by the largest value between Quantity and 1


MIN function

Returns the smallest value between two values.

Syntax:

 MIN(<expression 1>; <expression 2>)

Example:

 "Value" / MIN("Cost"; 100) - Divides Value by the smallest value between Cost and 100


POWER function

Returns the power of a value in a defined exponent. It can be used with only one parameter, in this case it considers the default exponent 2. If a second parameter is passed, this will be the exponent.

Syntax:

 POW(<expression>; <exponent>)

Examples:

 POW("Profit") - Returns the power of the Profit value.
 POW("Cost"; 3) - Returns the power of the Cost value, raised to 3


RANDOM function

Returns a random number within the range of values ​​passed as arguments.

Syntax:

 RANDOM(<start limit>; <end limit>)

Example:

 RANDOM(10,100) - Returns a random number between 10 and 100


SQRT function (Square Root)

Returns the square root of a value.

Syntax:

 SQRT(<value or expression>)

Examples:

 SQRT("Profit") - Returns the square root of the value Profit
 SQRT(81) - Returns the square root of 81


LIKE function

Returns true if the desired content is found in the list and false otherwise. It needs two parameters, the first is the data to query and the second is the term to be found. Remembering that it is necessary to use the wildcard operator “%” and surround the term by single quotation mark.

Syntax:

 LIKE(< data>; <term>)

Example:

 LKE("Product"; '%anh%') - Returns true if the Product contains the term anh or false otherwise


Date Functions

Date functions are operations that take a date as a parameter and also return a date. There are some constants to assist in using date functions, they are:

  • 0: DATE_FIELD_YEAR (Part of the year)
  • 1: DATE_FIELD_MONTH (Month Part)
  • 2: DATE_FIELD_DAY (Daypart)
  • 3: DATE_FIELD_FORTNIGHT (Part of fortnight)
  • 5: DATE_FIELD_WEEK (Part of the Week)


DATE_PART function (Date Part)

Returns part of a date. It needs two parameters, the first is the reference date and the second is the constant that represents which part of the date we want to get.

Syntax:

 DATE_ PART(<date>; <constant representing which part>)

Example:

 DATE_ PART("Issued Date"; 0) - Returns the year portion of the Issued Date


DAY_FROM_TODAY function (Days from today)

Returns a days count backward (negative) or forward (positive) from today. You need a parameter that indicates the number of days to add or subtract.

Syntax:

 DAY_FROM_TODAY(<number of days>)

Example:

 DAY_FROM_TODAY(-1) - Returns yesterday's date


FIRST_DAY_OF function (First day of)

Returns the first day of a grouping. This function has two variations:

  • With two parameters, the first is the grouping constant from which we want to get the first date (see list above), and the second is the base date.

Syntax:

 FIRST_DAY_OF(<date part>; <base date>)

Examples:

 FIRST_DAY_OF(0;DAY_FROM_TODAY(0)) - Returns the first day of the year from today
 FIRST_DAY_OF(1;"Issue Date") - First Day of Month Based on Issue Date Column
  • With three parameters, the first is the grouping constant from which we want to get the first date (see list above), the second is the date base modifier from today, and the third is the amount to change the modifier.

Syntax:

 FIRST_DAY_OF(<date part>;<date modifier>;<date modifier value>)

Example:

 FIRST_DAY_OF(1,0,-1) - first day of current month of last year


LAST_DAY_OF function (Last day of)

Returns the last day of a date grouping. This function has two variations.

  • With two parameters, the first is the grouping constant from which we want the last date (see list above), and the second is the base date.

Syntax:

 LAST_DAY_OF(<date part>; <base date>)

Examples:

 LAST_DAY_OF(0;DAY_FROM_TODAY(0)) - Returns the last day of the year from today.
 LAST_DAY_OF(1;"Date Issued") - Last day of month based on Date Issued column
  • With three parameters, the first is the grouping constant from which we want the last date (see list above), the second is the date base modifier from today, and the third is the amount to change the modifier.

Syntax:

 LAST_DAY_OF(<date part>;<date modifier>;<date modifier value>)

Example:

 LAST_DAY_OF(1,0,-1) - last day of current month of last year


NEW_DATE function (New date)

Creates a new date. It needs three parameters, the first corresponds to the day (between 1 and 31), the second month (between 1 and 12) and the third the year. The date is created from year to day, ie the day must be valid for the month and year (considering 29/02, the year must be leap).

Syntax:

 NEW_DATE(<day>;<month>;<year>)

Example:

 NEW_DATE(1;4;DATE_PART("Issued Date";0)) - Creates the first April day of the year determined by the current row in the Issued Date column.


NUM_OF_DAYS function (Number of days)

Returns the number of days between two dates. Therefore you need two dates.

Syntax:

 NUM_OF_DAYS(<date 1>; <date 2>)

Examples:

 NUM_OF_DAYS(FIRST_DAY_OF(0;"Issued Date");"Issued Date") - Returns the number of days from the first day of the year, based on the Issued Date column, to the current day, based on the same column.
 NUM_OF_DAYS(FIRST_DAY_OF(1;"Issued Date");LAST_DAY_OF(1,"Issued Date")) - Returns the number of days of the month, based on the Issued Date column.


NUM_OF_MONTHS function (Number of months)

Returns the number of months between two dates. Therefore, two date parameters are required.

Syntax:

 NUM_OF_MONTHS(<date 1>; <date 2>)

Example:

 NUM_OF_MONTHS(FIRST_DAY_OF(0; "Date"); "Date") - Returns the number of months between the first day of the year and the current month, based on the Date column.


PREVIOUS_DATE function (Previous date)

Given a day and a month, returns the last occurrence of that date. That is, if the current date (today) is less than the date passed by parameter (day / month), the return is the date (passed by parameter) of the previous year. Otherwise the return will be the current year date.

Syntax:

 PREVIOUS_DATE(<day>; <month>)

Examples:

 PREVIOUS_DATE(15;12) - Considering that today's date is 14/11/2019, the last time December 15th occurred relative to today's date was 15/12/2018, so this will be the return.


Special Variables

They can be used in conjunction with expressions to create complex calculations. Must be used in double quotation marks (“)


  • "@count" - Total number of rows that were returned for the component.
  • "@row" - Current row number
  • "@sum[column]" - Sum of the indicated column.
    • Example: "@sum[Price]" - returns the sum of all rows in the Price column.
  • "@avg[column]" - Average column, similar to "@sum[column]" / "@count"
  • "@prev[column]" - Row value before current row for this column
  • "@accumCol[column]" - Cumulative value from column to current row. Useful for calculating variable mean.
    • Example: "@accumCol[column]" / "@row"