When working with reports in IBM Planning Analytics for Excel (PAfE), we sometimes need to change the order of dimension members dynamically based on selected criteria. For example, we may want to sort Channels based on selected revenue values or other dimensional intersections. Instead of sorting the rows manually in Excel, we can use an MDX expression to define the required order dynamically.
In this example, the user chooses either ASC or DESC from a dropdown and then clicks a Refresh button. PAfE rebuilds the report rows using the selected sorting direction.
The MDX expression below is entered in cell B11. It retrieves the members of the Store dimension and sorts them using the selected period, measure and other dimension selections.
="{ORDER(DISTINCT(DRILLDOWNMEMBER({[Channel].[Channel].[Channel Total]},{[Channel].[Channel].[Channel Total]})),([Channel].[Channel].CurrentMember,[organization].[organization].["&$C$14&"],[Revenue].[Revenue].["&$C$15&"],[Year].[Year].["&$C$16&"],[Product].[Product].["&$C$18&"],[Version].[Version].["&C$17&"]),"&$E$20&")}"
DRILLDOWNMEMBER expands the specified consolidation and returns its individual members.
How the sorting value is determined
The tuple inside ORDER tells TM1 which cube intersection to use when it evaluates each member. In this example, the selected values come from these report cells:
|
Dimension |
Cell / reference |
Used for |
|
Channel |
CurrentMember |
Member being sorted |
|
organization |
C14 |
Selected organization |
|
Revenue |
C15 |
Selected revenue measure/member |
|
Year |
C16 |
Selected year |
|
Version |
C17 |
Selected version |
|
Product |
C18 |
Selected product |
Once the MDX set is ready, pass it to TM1RPTROW so the members appear as rows in the report.
=@TM1RPTROW($B$12,"24Retail:Channel",,,"Caption_Default",FALSE,B$11)
The reference B$11 points to the MDX expression. TM1RPTROW uses the set returned by that expression to build the report rows. To use this approach with another
dimension, update the dimension and hierarchy references in the MDX and the TM1RPTROW formula.
The dropdown gives the user a simple way to choose the sorting direction. In this example, cell E20 is used for the selection.
ASC means ascending order (lowest to highest). DESC means descending order (highest to lowest). The MDX expression reads the selected option through this reference:
"&$E$20&"
Changing the dropdown does not sort the report straight away. It only changes the value that will be used by the MDX expression when the report is rebuilt.
The Refresh button applies the selected sorting direction. Add an IBM Planning Analytics Action Button to the worksheet and configure it as follows:
Rebuild sheet is used because the report rows need to be generated again using the updated MDX set. Recalculate sheet recalculates existing values, but it does not serve the same purpose as rebuilding the Dynamic Report rows.
First — The MDX expression defines which members to retrieve and how their values will be compared.
Next — The user selects ASC or DESC from the dropdown.
Then — The user clicks the Refresh button.
Finally — PAfE rebuilds the report rows, applying the selected sorting direction.
Save the workbook as an Excel Macro-Enabled Workbook (*.xlsm). Select File → Save As, choose the .xlsm format and save the file. This keeps the workbook in the macro-enabled format used for the Action Button setup.
With MDX, TM1RPTROW, a dropdown and an Action Button, users can change the order of report members without sorting the rows manually. They choose ASC or DESC and click Refresh to rebuild the report in that order. The same idea can be adapted to other dimensions and reports by changing the relevant MDX references.