It is possible to use Data Selector objects in Aggregate Formulas.
Data Selectors can be referenced in Aggregate formulas, with the USING clause according to the following grammar:
<AggFormulaName> (<Expression>, [<AggregationCondition>], [<DefaultValue>])
View Syntax conventions
Could be take one of the following values: Find, Max, Min, Sum, Count, or Average.
Is an expression to be finded, maximized, minimized, summed or averaged. It can be an attribute (stored or formula), or an expression that involves attributes, variables and constants.
Is define as [<Condition>] [USING <DataSelector> '(' <Parameters...> ')']
Is the returned value when no records match the AggregateCondition. It is a constant and it is optional.
- For Count formulas, the first parameter can't be an expression. On the other hand, it must be an attribute.
- For Sum and Count formulas, the result of evaluating the Expression must be a numeric value.
- If using the DataSelector clase, it is not supported to use Procedures, otherwise the spc0026 will be detailed and the formula cannot be solved.
- User variables can only be used in inline formulas.
Suppose that you have "Customer" and "Country" Transactions, where each customer has a country. To count the number of active customers per country you only have to write the following:
For Each CountryId
&NumberActiveCustomers = Count(CustomerName, USING ActiveCustomers())
The "ActiveCustomers" Data Selector definition is as follows:
Something important to know is that the CustomerName attribute -the first parameter in the count formula- is not taken into account by GeneXus to determine the For Each Base Table. The CustomerName attribute belongs to the Formula definition.
The For Each base table is COUNTRY (because CountryId is the only attribute mentioned in the For Each command outside the formula definition).
The table navigated by the Formula (in which the calculation is made) is CUSTOMER (because the attributes mentioned in the formula and in the Data Selector definitions belong to the CUSTOMER table).
Finally, the two tables that are navigated, COUNTRY and CUSTOMER, have a common attribute: CountryId. So, for each navigated country (by the For Each command), the Aggregate Formula defined inside the For Each (inline) considers only the active customers that belong to the country being navigated in the For Each query, at the moment of triggering the formula.
Data Selectors in Grids
Data Selectors in Data Providers
Data Selectors in For Each command
Data Selectors in Web Panels
Work With List Node
Entry Panels as Filters for a List in Smart Devices