In EQL, you can define statements and then refer to these statements from other statements.
Multiple EQL sub-queries can be specified within the context of a single navigation query, each corresponding to a different analytical view, or to a sub-total at a different granularity level.
Expressions also can use values from other computed statements. This is often useful when coarser subtotals are required for computing analytics within a finer-grained bucket.
For example, when computing the percent contribution for each sales representative in a given year, you must also calculate the overall total for the year. You can use inter-statement references to create these types of queries.
<LookupExpr> ::= <statement name>[<LookupList>].<attribute name> <LookupList> ::= <empty> ::= <SimpleExpr> [,<LookupList>]
The square brackets are used to identify the record set and grouping attribute, and the dot is used to identify the field.
For example, suppose we want to compute the percentage of sales per ProductType per Region. One aggregation computes totals grouped by Region, and a subsequent aggregation computes totals grouped by Region and ProductType.
This second aggregation would use expressions that referred to the results from the Region aggregation. That is, it would allow each Region and ProductType pair to compute the percentage of the full Region subtotal represented by the ProductType in this Region.
DEFINE RegionTotals AS SELECT SUM(Amount) AS Total GROUP BY Region RETURN ProductPcts AS SELECT 100 * SUM(Amount) / RegionTotals[Region].Total AS PctTotal GROUP BY Region, ProductType
This example computes for each quarter the percentage of sales for each product type.
This query requires calculating information in one statement in order to use it in another statement.
DEFINE QuarterTotals AS SELECT SUM(Amount) AS Total GROUP BY Quarter ; RETURN ProductPcts AS SELECT 100 * SUM(Amount) / QuarterTotals[Quarter].Total AS PctTotal GROUP BY Quarter, ProductType