Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
AGajreeFM
New Member

Sort a Dimension Table with a measure where some rows in the Dimension Table will have a blank value

Hi

I want to sort a Dimension Table by a measure, lets say [Total Sales], but some rows in the dimension table have no sales so this meant an attempt with RANKX didn't work as that provided ties and meant I could not sure the Sort By Column as values must be unique

Can anyone advise or point to a blog or article?

Thanks in Advance

5 REPLIES 5
v-mengmli-msft
Community Support
Community Support

Hi @AGajreeFM ,

 

According to your description, you want the values in the slicer to be sorted by the corresponding sales amount. If I understand you correctly, you can consider creating Sorting table. Here is my test for your reference.

1. Calculate the sales corresponding to the product.

vmengmlimsft_0-1739954857090.png

2. Sort sales column.

vmengmlimsft_1-1739954933936.png

3. Creating the Sorting Table and have the product column sorted by the rank column.

vmengmlimsft_3-1739955031683.png

Then use the product column of the Sorting Table in the slicer and select the sort order. Alternatively, you may need to create a relationship between the Sorting Table and the Fact Table to enable filtering.

vmengmlimsft_4-1739955292380.png

If the above is not what you want, please provide data and examples to explain the results you want.

 

 

 

 

 

 

——————————————————————————————————————————————————

If my answer helps you solve the problem, please accept my answer as a solution and let it be seen by more people in need.

 

Best regards,

Mengmeng Li

amitchandak
Super User
Super User

@AGajreeFM , You have sort option on visual to sort based on measure. Recently its has been added for Legends too under properties.

 

Only for Matrix visual column, you do no have option sort based on measures.

 

amitchandak_0-1739874273703.png

Sort by values for legend

amitchandak_1-1739874314439.png

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi

I wish to sort the slicer in descending order of sales, so not the visual

rohit1991
Super User
Super User

Hi @AGajreeFM ,

 

To sort a Dimension Table by a measure (e.g., Total Sales) in Power BI while handling blank values and ensuring unique rankings, you can modify your RANKX approach to avoid ties and blank values. The issue arises because RANKX assigns the same rank to multiple rows with the same measure value, and Power BI’s Sort By Column requires uniqueness.

 

You can create a calculated column using RANKX while incorporating a secondary sort condition (like an ID column) to break ties:

RankedSales = 
VAR SalesRank = 
    RANKX(ALL('DimensionTable'), [Total Sales], , DESC, DENSE)
VAR UniqueRank = 
    SalesRank + DIVIDE(DISTINCTCOUNT('DimensionTable'[ID]), 1000000)
RETURN 
    IF([Total Sales] = BLANK(), BLANK(), UniqueRank)

This method ensures unique ranking, correct sorting, and proper handling of blank values, allowing your Dimension Table to be sorted accurately by Total Sales without violating Power BI’s Sort By Column constraints.

 

Passionate about leveraging data analytics to drive strategic decision-making and foster business growth.
Connect with me on LinkedIn: Rohit Kumar

Thannk you for your reply but I need a unique rank for the blank values too otherwise I cannot use the SortByColumn on the dimension table with the new calculated column as that needs unique values?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.