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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
SriKandimalla
Helper I
Helper I

How to sort TopN results based on a column not used in the function

Hello Power BI Community, 

Happy New Year to all!

 

I am trying to get a solution for a peculiar request. I am populating a measure in matrix to get a skyline chart. 

 

My DAX measure is as follows:

Skyline_Names =
var Rank = SELECTEDVALUE( Skyline[Rows] )
var Count = DISTINCTCOUNT( Table1[Name] )
var stage = SELECTEDVALUE(Table1[Stages])
RETURN
IF (
NOT ISBLANK ( Rank ),
IF (
Rank <= Count,
LASTNONBLANK (
TOPN ( Rank, VALUES(Table1[Name]),Table1[Name],ASC)
,0
)
),
stage
)
 
Now, this is all fine and the values in matrix are sorted based on the alphabetical order of the Table1[Name], but I need to sort based on a different column. I highlighted the part where I need to sort based on a different column eg: Table1[Price].
 
I tried multiple functions like SELECTCOLUMN, RANKX, etc.. but did not succeed.
I am including the source and PBIX file
 
I really appreciate if you have any suggestions or can help me with this. Thank you in advance!
@v-yangliu-msft @amitchandak @Greg_Deckler @ValtteriN 

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @SriKandimalla ,

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-yangliu-msft 

 

Thank you for your response. I am still trying to figure it out, but did not succeed. I amincluding the source file and the pbix file.

https://drive.google.com/drive/folders/1VdxQRTty-kxuHvurB8o-2cJkFhgcw2El?usp=sharing 

 

I created a measure based on the DAX above. Now when I plot the measure in a matrix the way I did. I have to sort the measure values based on a column "cost". Since I am using the TopN, I could not able to sort teh result of TopN based on a column that is not the project. I only can output 1 column, instead of a tabel with TopN. Please check the file and you would understand.

 

Thank you

amitchandak
Super User
Super User

@SriKandimalla , In Matrix you can sort on rows or measure (values) total using three dots.

 

You can not mark a measure a sort column of Name

 

amitchandak_0-1641524876107.png

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hello @amitchandak

 

Thank you for your response!

 

I cannot use the sort option from the matrix visual menu, It does not apply in my case because the values in the measure are only being sorted based on the alphabetical order.

 

The solution I am looking for is how to sort the values in the measure using DAX in the above expression. 

 

Thank you

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Solution Authors