Being able to think in sets is the key to being able to write more advanced queries and calculations in MDX. It’s not possible to write procedural code in MDX; instead you have to use functions that return sets and members to express what you want to appear on rows or columns in a query, and to express more complex transformations inside your calculations.
Chris Webb introduces the commonest MDX functions that return sets in this 40-minute, demo-driven video, starting with the .MEMBERS function and the CROSSJOIN() function.
When used with a hierarchy, the .MEMBERS() function returns a set consisting of all the members on that hierarchy; when used with a level on a hierarchy it returns a set containing all of the members on that level. The CROSSJOIN() function takes two or more sets, and it returns a set of tuples containing all of the possible permutations of the members in each set.
Another very useful family of functions are those that allow you to move up, down, forwards and backwards in a hierarchy, and which return a set, or a member relative to another member: the hierarchical functions. To move up or down the hierarchy, you can use the .PARENT function, which returns the member immediately above a member in the hierarchy, or the .CHILDREN function, which returns the set of members underneath a member. You can also use the DESCENDANTS() function to return the complete set of members underneath a member at every level of the hierarchy or at a particular level and the ANCESTOR() function to return the ancestor of a member above it in a hierarchy at a given level. To move one member forwards, or backwards along a level from a given member, you can use the .NEXTMEMBER and .PREVMEMBER functions, while to move forwards or backwards more than one member you can use the .LEAD() and .LAG() functions. Finally, to find the set of members between two members on the same level of a hierarchy you can use the range operator, a colon (:).
Make sure to watch, and to follow Chris’s examples from this video, as these are some of the most useful, and fundamental MDX functions you will need in your work.