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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DaxPadawan
Helper III
Helper III

Sorting of values per month per group in a matrix

Hello! This is actually related to a previous question

 

This is how the data looks. 

CategoryTypeScoreMonthRanking
A1100Jan 20211
A250Jan 20212
B375Jan 20211
B180Feb 20212
B390Feb 20211
C260Feb 20211
C355Mar 20211
C140Mar 20212

 

Now, I put the data into a matrix with the Category and Type as rows, Month as the columns, and Score/Ranking as the values (I plan to use a field parameter to switch between the two). It looks like this: 

CategoryTypeJan 2021Feb 2021Mar 2021
A1100  
 250  
B1 80 
 37590 
C1  55
 2 60 
 3  40

 

What I want to do now is to be able to sort by Score (or Rank, but that's essentially the same thing) for a specific month. For example, if I want to sort by February:

CategoryTypeJan 2021Feb 2021 (sort)Mar 2021
A1100  
 250  
B37590 
 1 80 
C2 60 
 1  55
 3  40

 

If it is relevant, Score is a regular column while Ranking a measure. Category, Type, and Month are regular columns as well. Thank you in advance!

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @DaxPadawan ,

 

Please create two measures:

_Score = 
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Score] ), FILTER ( 'Table', MONTH ( [Month] ) = 2 ) )
RETURN
    IF ( ISINSCOPE ( 'Table'[Month] ), SUM ( 'Table'[Score] ), _sum )



_Rank = 
VAR _rank =
    RANKX (
        FILTER (
            ALL ( 'Table' ),
            [Category] = SELECTEDVALUE ( 'Table'[Category] )
                && [Month] = SELECTEDVALUE ( 'Table'[Month] )
        ),
        CALCULATE ( SUM ( [Score] ) ),
        ,
        DESC,
        DENSE
    )
VAR feb_rank =
    MAXX ( FILTER ( 'Table', MONTH ( 'Table'[Month] ) = 2 ), _rank )
RETURN
    IF ( ISINSCOPE ( 'Table'[Month] ), _rank, feb_rank )

 

Create a field parameter:

vyadongfmsft_0-1669256789677.png

 

You will see:

vyadongfmsft_1-1669256883496.png

vyadongfmsft_2-1669256933546.png

 

You can sort by February:

vyadongfmsft_3-1669256975887.png

 

If you don't want to show column subtotals, you can switch off subtotals after sorting:

vyadongfmsft_4-1669257131653.png

 

Best regards,

Yadong Fang

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

View solution in original post

3 REPLIES 3
v-yadongf-msft
Community Support
Community Support

Hi @DaxPadawan ,

 

Please create two measures:

_Score = 
VAR _sum =
    CALCULATE ( SUM ( 'Table'[Score] ), FILTER ( 'Table', MONTH ( [Month] ) = 2 ) )
RETURN
    IF ( ISINSCOPE ( 'Table'[Month] ), SUM ( 'Table'[Score] ), _sum )



_Rank = 
VAR _rank =
    RANKX (
        FILTER (
            ALL ( 'Table' ),
            [Category] = SELECTEDVALUE ( 'Table'[Category] )
                && [Month] = SELECTEDVALUE ( 'Table'[Month] )
        ),
        CALCULATE ( SUM ( [Score] ) ),
        ,
        DESC,
        DENSE
    )
VAR feb_rank =
    MAXX ( FILTER ( 'Table', MONTH ( 'Table'[Month] ) = 2 ), _rank )
RETURN
    IF ( ISINSCOPE ( 'Table'[Month] ), _rank, feb_rank )

 

Create a field parameter:

vyadongfmsft_0-1669256789677.png

 

You will see:

vyadongfmsft_1-1669256883496.png

vyadongfmsft_2-1669256933546.png

 

You can sort by February:

vyadongfmsft_3-1669256975887.png

 

If you don't want to show column subtotals, you can switch off subtotals after sorting:

vyadongfmsft_4-1669257131653.png

 

Best regards,

Yadong Fang

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

DaxPadawan
Helper III
Helper III

Sorry @amitchandak, I'm not sure what you mean. 

amitchandak
Super User
Super User

@DaxPadawan , if this a matrix visual, then you sort on the row total on values or on row columns

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors