Expressões

From TaticView
Revision as of 20:06, 8 April 2014 by Artur (talk | contribs) (Created page with "As funções básicas são funções padrão do sistema e implementam funcionalidades úteis.")
Jump to: navigation, search

Expressões permitem que você crie e edite regras de Filtros manualmente usando linguagem de programação.

Importante: Depois de editar manualmente a expressão, os operadores regulares não podem ser usados até que você Limpe todos os filtros;



Estruturas de Expressões Básicas

Operandos de Valor

Os operandos de valor são valores de um tipo de dado que são usados nas expressões como variáveis.


Operando de Valor

São valores numéricos do tipo float (domínio dos números Reais). Estes valores permitem o uso de um integer e uma parte fracionada, separada por um ponto (.) (separador decimal).

 Exemplos: 1, 1.05, 2.55;

Operando de Texto

São operandos de dados de cadeia literais. Estes valores permitem o uso de campos de sequência de caracteres(strings), sendo delimitados pela aspas simples (').

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

Operando de Data

São valores que expressam qualquer data. É possível representar a data como uma string, sendo delimitada pela aspa simples (') e separado pela barra (/). O formato padrão suportado é "dd/MM/aaaa".

 Exemplos: '01/01/2011', '29/02/2000';

Operando Booleano

São valores do tipo verdadeiro ou falso. Normalmente usados para validar, ou não, uma condição.

 Exemplos: true e false;

Operandos de Identificação

São valores que representam um campo ou variável na expressão. Usados para fazer referências para as colunas da fonte de dados, delimitado por aspas duplas (").

 Exemplos: "Cidade.Cidade", "Produto.Produto";

Parênteses

Usados para agrupar e separar partes da expressão. Expressões dentro do parênteses são processadas antes.

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

Operando de variável de sistema

São variáveis pré-definidas do sistema. Estes valores são alterados em tempo de execução por valores pré determinados, delimitado por aspas duplas (") e precedido por cerquilha (#). Agora somente uma variável está disponível: "#null", que indica valores ou campos nulos.


Expressões Aritméticas

As relações aritméticas relacionam dois operandos (valor ou outra expressão) para compor a soma, subtração, multiplicação ou divisão.

Soma (+)

Soma dois operandos. Representado pelo caractere de soma (+).

  Sintaxe: <operando/expressão> + <operando/expressão>.
 Exemplos: "Impostos" + "Comissões";

Subtração (-)

Subtrai dois operandos. Representado pelo caractere de soma ou hífen (-).

  Sintaxe: <operando/expressão> - <operando/expressão>.
 Exemplos: "Preço" - "Impostos";

Multiplicação (*)

Multiplica dois operandos. Representado pelo caractere de multiplicação ou asterisco (*).

  Sintaxe: <operando/expressão> * <operando/expressão>.
 Exemplos: "Quantidade" * "Preço Unitário";

Divisão (/)

Divide dois operandos. Representada pelo caractere de divisão ou barra (/).

  Sintaxe: <operando/expressão> / <operando/expressão>.
 Exemplos: "Preço" ; "Quantidade".


Expressões Relacionais

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

Igual (==)

Executa a a comparação de igualdade entre dois operandos. Representado pelo operador de igualdade (==).

  Sintaxe: <expressão> == <expressão>.
 Exemplos: "Preço Unitário" == "Preço Total";

Diferente (!=)

Executa a comparação de diferença entre dois operandos. Representado pelo operador Diferente (!=).

  Sintaxe: <expressão> != <expressão>.
 Exemplos: "Cidade.Cidade" != 'São Paulo';

Maior que (>)

Retorna true (verdadeiro) se a primeira expressão é maior que a segunda expressão e false(falsa) caso contrário. Representado pelo operador maior (>).

  Sintaxe: <expressão> > <expressão>.
 Exemplos: "Data de Pedido" > '01/01/2011';

Maior ou igual que (>=)

Retorna true (verdadeiro) se a primeira expressão é maior ou igual que a segunda expressão e false(falsa) caso contrário. Representado pelo operador maior ou igual (>=).

  Sintaxe: <expressão> >= <expressão>.
 Exemplos: IF("Data de Pedido" >= '01/01/2011';"Data de Pedido";0);

Menor que (<)

Retorna true (verdadeiro) se a primeira expressão é menor que a segunda expressão e false(falsa) caso contrário. Representado pelo operador menor (<).

  Sintaxe: <expressão> < <expressão>.
 Exemplos: "Lucro" < '0';

Menor ou igual que (<=)

Retorna true (verdadeiro) se a primeira expressão é menor ou igual que a segunda expressão e false(falsa) caso contrário. Representado pelo operador menor ou igual (<=).

  Sintaxe: <expressão> <= <expressão>.
 Exemplos: IF("Data de Pedido" <= '01/01/2011';"Data de Pedido";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 true(verdadeiro) ou false(falso). Normalmente usado com funções de decisão, como IF e com expressões relacionais.


E (&&)

Executa a operação lógica E entre dois valores booleanos. Ambos operadores devem ser true(verdadeiro) para que o resultado da operação seja true. Representado pelo operador E (&&).

  Sintaxe: <expressão> && <expressão>.
 Exemplos: IF((Preço > '0') && (Vendedor == 'André Moraes');'Vendido';'Não Vendido'), IF((Cidade!="#null") && (Date<DAY_FROM_TODAY(0));1;0);

Ou (||)

Executa a operação lógica OU entre dois valores booleanos. Um dos dois valores deve ser true para que o resultado da operação seja true. Representado pelo operador OU (||).

  Sintaxe: <expressão> || <expressão>.
 Exemplos: IF((Preço > '0') || (Vendido == 'true');'Vendido';'Não Vendido'), IF((Cidade!="#null") || (Date<DAY_FROM_TODAY(0));1;0);

Não (!)

Executa a operação lógica de negação para um valor booleano. Se o operando for true o NÃO converte ela para false e vice-versa. Representado pelo operador NÃO (").

  Sintaxe: ! <expressão>.
 Exemplos: IF(!BETWEEN("Data", '01/01/2013', '31/12/2013');'Não é 2013';'É 2013').


Funções Auxiliares

Funções Básicas

As funções básicas são funções padrão do sistema e implementam funcionalidades úteis.

Abs

Returns the absolute value of a base value.

   Syntax: ABS(<expression>). Accept one parameter and process a numeric data type. 
 Examples: ABS(Gross Sale-Taxes);

Avg

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

Check if a value is inside 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

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

Returns the log value of a number on a set base.

   Syntax: LOG(<expression_number>[;<expression_base>]). Minimum one parameter and maximum two. If just one parameters is given, the 
           neperian log is returned. If the second parameter is also given, returns the log in the respective base. 
 Examples: LOG(Profit);

Max

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

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

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

Returns a 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

Returns the square root of a value.

   Syntax: SQRT(<expression>). Need one parameters, the value to be calculated. 
 Examples: SQRT('36').


Date Functions

The date functions are operations that use as parameters and return result of the date data type.

Constants list

    • 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

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

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

Return the first day of a grouping. This function have 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

Return the last day of a grouping. This function have 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

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

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

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

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".