Generate

Returns a set formed by evaluating a set expression. For each tuple in set1, return set2.

Syntax

Generate ( set1, set2 [, [ALL]] )
ParameterDescription

set1

The set to loop through.

set2

The set expression to evaluate for every tuple in set1.

ALL

If the optional ALL flag is used, duplicate tuples are retained.

Notes

The set expression set2 is evaluated in the context of each of the tuples from set1. The resulting sets are combined, in the same order as of the tuples in set1, to produce the output. Duplicates are not included by default.

Example

For each region of the market, return its top-selling 3 products. Display the sales data by quarter.

WITH SET [Top3BevsPerRegion] 
AS 
 'Generate ({[Market].children},
  Crossjoin 
   (
   {[Market].Currentmember}, 
    TopCount 
     (
      [Product].Members, 3, [Measures].[Sales]
     )
   )
 )' 
SELECT
 {[Top3BevsPerRegion]}
ON COLUMNS, 
 {[Year].children}
ON ROWS
FROM Sample.Basic
WHERE ([Scenario].[Actual], [Measures].[Sales])
(axis)EastWestSouthCentral
(axis)ProductColasRoot BeerProductDiet DrinksCream SodaProductRoot BeerDiet DrinksProductDiet DrinksColas
Qtr120621629257263167488208043121135354448331412105448074
Qtr2224499723059023357290868982126025535497633056108098701
Qtr322976777058633513095189616133555690494733754109598894
Qtr421352644861813255589998750127765429445031458103488139