Generate

Returns a concatenated string created by evaluating a string expression over a set.

Applies a set to each element of another set and joins the resulting sets by union. Alternatively, returns a concatenated string created by evaluating a string expression over a set.

Syntax

Set Generate(«Set1», «Set2»[, ALL])

String Generate(«Set», «String Expression»[,«Delimiter»])

The set version of this function applies «Set2» to each element of «Set1» and joins the resulting sets by union. If ALL is specified, duplicates in the result are retained.

The string version of this function iterates through each element of the set specified in «Set», evaluates a string expression, specified in «String Expression», against the element and concatenates the result into the return string. Optionally, the string can be delimited by supplying a string expression in «Delimiter», separating each result in the concatenated return string.

Set examples

Generate({USA, France}, Descendants(Geography.CurrentMember, Cities))

For each element of the set {USA, France}, this function applies the expression Descendants(Geography.CurrentMember, Cities). Each such application results in a set. (Application to USA generates the set of all cities in USA; application to France generates all cities in France.) These sets are joined by union to return the result of this function. In this example, all cities in USA and France are the result. In general, Generate(«Set1», «set_expression») applies «set_expression» to each element of «Set1» and join the results by union.

If «Set1» is not related to «set_expression» by means of CurrentMember, then Generate results in a simple replication of the set implied by «set_expression», with as many replications as there are tuples in «Set1». If the optional ALL flag is specified, all duplicates are retained in the result. If ALL is not specified, duplicates are removed. For example:

Generate({USA, FRANCE}, {SEATTLE, BOSTON}, ALL)

returns the set:

 {SEATTLE, BOSTON, SEATTLE, BOSTON}

However, if ALL was not specified, then this set is returned:

 {SEATTLE, BOSTON}

String examples

This example returns the string "19971998":

Generate( {Time.[1997], Time.[1998]}, Time.CurrentMember.Name)

This example returns the string "1997 and 1998":

Generate( {Time.[1997], Time.[1998]}, Time.CurrentMember.Name, " and ")