PREVMEMBER (MDX)
Returned Type
This function returns a member.
Syntax and Details
member_expression.PREVMEMBER
Where:
-
member_expression is an expression that returns a member.
This expression cannot refer to a measure.
This function examines the members of the level to which the given member belongs, and returns the previous member of that set (considering the default order of that set). For time dimensions, this function ignores any parent level. For data dimensions, this function considers the parent level; it counts backward from the current member within the given parent member. (Note that the terms time dimension and data dimension refer specifically to the dimension type as defined in the cube. See Defining Models for InterSystems Business Intelligence.)
The PREVMEMBER function is equivalent to LAG(1).
Within any time dimension, this function is more useful for a timeline-based time level (such as Period, which groups records by year and month) than for a date-part-based time level (such as Month, which groups records only by month). See the examples. For a fuller discussion, see Introduction to Time Levels.
Example
The first examples use a time dimension. Consider the following query, shown for reference:
SELECT MEASURES.[%COUNT] ON 0,
{birthd.1948,birthd.1949,birthd.1950,birthd.1951,birthd.1952} ON 1
FROM patients
Patient Count
1 1948 10
2 1949 4
3 1950 12
4 1951 8
5 1952 6
The following query uses PREVMEMBER:
SELECT MEASURES.[%COUNT] ON 0, birthd.1951.PREVMEMBER ON 1 FROM patients
Patient Count
1950 12
For another example:
SELECT MEASURES.[%COUNT] ON 0, birthd.1950.PREVMEMBER ON 1 FROM patients
Patient Count
1949 4
In this sample, the year level is the child of the decade level, which means that the members 1949 and 1950 belong to different parents. As you can see, the PREVMEMBER function ignores the parent level when you use the function with a time dimension.
The second examples use a data dimension (the HomeD dimension). To see the hierarchy in this dimension, see the examples in the FIRSTCHILD function. The following query uses PREVMEMBER with this dimension:
SELECT MEASURES.[%COUNT] ON 0, homed.city.Magnolia.PREVMEMBER ON 1 FROM patients
Patient Count
Cypress 104
Because this is a data dimension, this query retrieves the previous member of the city level within the parent ZIP code. Within this ZIP code, Cypress is the first city, so the following query returns no results:
SELECT MEASURES.[%COUNT] ON 0, homed.city.Cypress.PREVMEMBER ON 1 FROM patients
Patient Count
*
For time level that is based on part of the date, this function returns null for the first member of the level. Consider the Month level, which groups records only by month. When we use this function with January, the engine returns null:
SELECT [BirthQD].[H1].[Month].[January].PREVMEMBER ON 1 FROM patients
*
For an example that uses PREVMEMBER to get the number of units sold in a previous time period, see %CELLZERO.