
上QQ阅读APP看书,第一时间看更新
Provide automatic sorting
The goal of this example is to provide automatic sorting of an attribute in report visuals. Specifically, the United States regional organizations should appear next to one another by default in visuals. By default, the Central Division (a part of the USA), appears between Canada and France given the alphabetical sorting of text columns:
- Add a Table.Sort() expression to the import query for the Organization dimension.
- The columns for the sort should be at the parent or higher level of the hierarchy.
- Add an expression with the Table.AddIndexColumn() function that will add a sequential integer based on the table sort applied in step 1.

Figure 43: Sort Order and Index Column Expressions
- With this expression, the Source dimension is first sorted by the Parent Organization column and then by Organization Currency. The new index column starts at the first row of this sorted table with an incremental growth of 1 per row.

Figure 44: Modified Organization Dimension Query
- In the Data View, select the Organization column.
- From the Modeling tab, set the Sort by Column dropdown to the index column created in step 2.

Figure 45: Sort By in Data View
- Finally, right-click on the OrgSortIndex option and select Hide in Report View.
- Visuals using the Organization column will now sort the values by their parent organization such that the USA organizations appear together (not alphabetically).

Figure 46: Organization Automatically Sorted