THIS
Syntax
THIS (Expression)
Description
The THIS function returns the value of Expression for the members being calculated, even if Expression is used in a database function. This function enables you to perform complex calculations that relate other members in a dimension to the member being calculated.
To understand the THIS function, you need to understand how database functions work. A database function scans the members in a dimension to calculate a result. For example, suppose that you define the following formula:
DAVG(PRODUCTS, ADVERTISING, SALES > 50000)
This formula calculates the average advertising for products with sales over 50000 USD. The DAVG function scans the PRODUCTS dimension and evaluates the condition SALES > 50000 for each product. If the condition is true, the DAVG function includes the Advertising for that product in the average. The important point here is that the DAVG function evaluates the condition (SALES > 50000) and the expression (Advertising) for the product being scanned.
Now suppose that you want to calculate the following result for each product: the average advertising for products whose sales are greater than the product being calculated.
Create a data cube called AVG_ADVERTISING_FOR_BETTER_PERFORMERS that uses the PRODUCTS dimension. Its formula should look similar to:
DAVG(PRODUCTS, ADVERTISING, SALES > "Sales for the product being calculated")
To get the sales for the product being calculated, remember that the DAVG function uses the sales for the product being scanned. The solution is to use the THIS function:
DAVG(PRODUCTS, ADVERTISING, SALES > THIS(SALES))
The THIS function forces the DAVG function to use the sales for the product being calculated. Thus, the condition compares the sales for the product being scanned to the sales for the product being calculated. If the condition is true, the DAVG function includes the Advertising for the product being scanned.
Returns
The value of Expression for the members being calculated, even if Expression is used in a database function.