Custom sort

Most dimension columns used in reports contain text values, and, by default, Power BI sorts these values alphabetically. To ensure these columns follow their logical order (for example, Jan, Feb, Mar) in report visualizations, it's necessary to store a corresponding column in the same dimension table and at the same granularity. For example, in addition to a Calendar Month column that contains the 12 text values for the names of the months, a Calendar Month Number column is included in the date dimension with the value of 1 for every row with the January value for Calendar Month, and so forth. 

To set a custom sort order for a column, select the column in the fields list in Report View and then click the dropdown for the Sort By Column icon under the Modeling tab. Choose the supporting column that contains the integer values, such as Calendar Month Number, as shown in the following screenshot:

 
Sort by Column

Most columns used as a Sort by Column are not needed for report visualizations and can be hidden from the fields list. Per the Date Dimension View section in Chapter 2Connecting to Sources and Transforming Data with M, sequentially increasing integer columns are recommended for natural hierarchy columns, such as Calendar Yr-Mo, as these columns can support both logical sorting and date intelligence calculations. 

Although the Calendar Month and weekday columns are the most common examples for custom sorting, other dimension tables may also require hidden columns to support a custom or logical sort order. In the following example, an integer column is added to the Customer dimension M Query to support the logical sort order of the Customer History Segment column:

                              /*Preceding M query variables not included*/
//Customer History Segment Column
CustomerHistoryColumn = Table.AddColumn(Customer, "Customer History Segment", each
if [Customer First Purchase Date] >= OneYearAgo then "First Year Customer"
else if [Customer First Purchase Date] >= TwoYearsAgo and [Customer First Purchase Date] < OneYearAgo then "Second Year Customer"
else if [Customer First Purchase Date] >= ThreeYearsAgo and [Customer First Purchase Date] < TwoYearsAgo then "Third Year Customer"
else "Legacy Customer", type text),

//Customer History Segment Column Sort
CustomerHistColSort = Table.AddColumn(CustomerHistoryColumn, "Customer History Segment Sort", each
if [Customer First Purchase Date] >= OneYearAgo then 1
else if [Customer First Purchase Date] >= TwoYearsAgo and [Customer First Purchase Date] < OneYearAgo then 2
else if [Customer First Purchase Date] >= ThreeYearsAgo and [Customer First Purchase Date] < TwoYearsAgo then 3 else 4, Int64.Type)
in
CustomerHistColSort

With the integer column (Customer History Segment Sort) added to the Customer dimension table and the Sort by Column property of the Customer History Segment column set to reference this column, Power BI reports visualize the Customer History Segment column by the logical order of the four possible values (First Year Customer, Second Year Customer, Third Year Customer, and Legacy Customer) by default. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.72.245