Sort Method

Sorts columns, layers, or rows in ascending or descending order.

Syntax

collection.Sort SortBy, OppDimIndex [, Order[, AutoSort]]

Applies To

Columns

Layers

Rows

Discussion

Sort arranges data according to criteria set in the parameters. You can sort by values or labels of a column or row, or by the labels of layers. Sorting can be automatic.

In automatic sort mode (AutoSort = True), drilling up or down causes an automatic re-sort of the data using the current parameter settings. If automatic sort mode is not on (AutoSort = False), drilling up or down does not cause a re-sort of the data. Items that are already sorted and any new or changed values remain in the order in which they appear.

There is only one active ordering action per Dimension object; that is, the user can sort by labels or values, but not both, in the same report dimension.

Sort behaves differently from the Rank2 method in that it doesn't actually add anything to the Report object; it simply re-orders what the user sees on the screen. Rank2 adds a rank sequence column or row to the report.

The sort method always sorts categories that have been suppressed or hidden, since they still exist as part of the report.

Do not use the OppDimIndex parameter when sorting on layers.

When any of these parameters are not included, the equivalent Preferences setting is used.

Parameters

Description

SortBy

Required. Specifies what to sort by.

0 = no sort 1 = sort by label 2 = sort by value (not valid for layers)

If 0 is set, the other three parameters have no effect.

Type: Variant

OppDimIndex

Required. Specifies the column or row on which to sort the data. It is always the opposite dimension; that is, rows use a column index and columns use a row index. The index starts at 1. This parameter is not valid for layers.

Type: Variant

Order

Optional. Specifies how to sort the categories. If not used, the Preferences setting is used.

1 = descending, 2 = ascending

Default: descending

Type: Variant

AutoSort

Optional. Specifies if rows are sorted automatically when the report changes. If not used, the Preferences setting is used.

False (does not auto-sort) True (auto-sorts)

Type: Boolean

Return Type

Nothing

Example

This example sorts columns by the values of the last row.

Sub Main()
   Dim objPPRep As Object
   Dim intRowIndex As Integer
   Const SortByValue = 2
   Const Descending = 1
   Const NoAutoSort = 0
   Set objPPRep = GetObject(, "CognosPowerPlay.Report")
   intRowIndex = objPPRep.Rows.Count
   objPPRep.Columns.Sort _
      SortByValue, intRowIndex, Descending, NoAutoSort
   Set objPPRep = Nothing
End Sub

Related Topics