Blog

How to sort date hierarchies in descending order in a hierarchical slicer in Power BI

In the world of business intelligence, the ability to efficiently analyze data from complex systems such as Microsoft Dynamics NAV (also known as Navision) and Business Central is critical. In Power BI, hierarchical slicers are a powerful tool to effectively filter and analyze data. A common challenge is to sort all levels of a date hierarchy (such as year and month) simultaneously in descending order. Although Power BI Slicer normally only sorts by a single field, there is a way around this problem and achieve a descending sort across multiple levels of the hierarchy.

Fundamental challenges

By default, Power BI Slicer can only sort by one field, which means that descending sorting across multiple hierarchy levels (such as year to month) is not directly supported. This restriction can lead to difficulties when analyzing time series data.

Solution: Sorting in the data view

A practical solution is to sort directly in the data view of Power BI. This approach involves manually sorting the weeks first by year and then by other temporal hierarchies. Here are the steps:

Step 1: Preparing the data

Make sure that your data source contains timestamps that are split into separate fields for year, month, week etc.. This is important for effective sorting.

Step 2: Create a custom sort order

In the data view, create a new column that combines the timestamps in a format that allows for descending sorting. For example, a column can be created that combines the year and month in a single value (e.g. 202212 for December 2022).

Step 3: Applying the sorting

Use this new column to sort your data in descending order. This column will serve as the basis for sorting the hierarchy levels in the slicer.

Step 4: Setting up the hierarchical slicer

Create a hierarchical slicer in your report and add the sorted fields in the desired order. The slicer now displays the data in the descending order defined in step 3.

Concluding thoughts

This method requires some manual steps and careful preparation of your data. However, it provides an effective way to work around the limitations of the standard slicer sorting in Power BI. With this technique, you can achieve an intuitive and user-friendly display of your time series data, making analysis and reporting much easier.