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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
KW123
Helper V
Helper V

Measure for Sorting which differs each month

Hi!

I need to build a table?? matrix?? that involves displaying each month in a singular visual. 

Each month there is a new ranking of names depending on how much $ sold.  I can't seem to figure out how to display each Month with changing names. I have tried a matrix, the problem is that the rows need to be in the values field as each month the rank will change.  (There are about 50 or so names each month, this is a small scale example)

Below is an example: 

 Month   Placing   Name   $  Sold   Month   Placing   Name   $  Sold   Month   Placing   Name    $ Solc  
January   1Bob100February   1Sally200March   1Joan187
January   2Sally75February   2Sam156March   2Travis178
January   3John50February   3Bob134March   3Sally154
January   4Joan48February   4Joan123March   4Sam134
January   5Travis30February   5John100March   5Bob125
January   6Sam10February   6Travis56March   6John110


Is there some sort of DAX that would be able to work with this? 

Any input would be appreciated!

3 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @KW123 

Create the following calculated table 

Placing = GENERATESERIES ( 1, 100, 1 )

 

Add a matrix visual. Place 'Table'[Month] in the columns and Placing[Value] in the rows. Don't panic when you see the error 😊

create the flowing measures and place them in the values of the matrix. 

Name Measure =
VAR T1 =
SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
COUNTROWS ( T1 )
VAR CurrentPlacing =
MAX ( Placing[Value] )
VAR Result =
IF (
CurrentPlacing <= NameCount,
MAXX (
TOPN (
1,
TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
[@Sold], ASC,
'Table'[Name], DESC
),
'Table'[Name]
)
)
RETURN
Result

$Sold New Measure =
VAR T1 =
SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
COUNTROWS ( T1 )
VAR CurrentPlacing =
MAX ( Placing[Value] )
VAR Result =
IF (
CurrentPlacing <= NameCount,
MAXX (
TOPN (
1,
TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
[@Sold], ASC,
'Table'[Name], DESC
),
[@Sold]
)
)
RETURN
Result

Month Measure =
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( 'Table'[Month] ) )

You may also want to add the Placing

Placing Measure =
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( Placing[Value] ) )

View solution in original post

Anonymous
Not applicable

Hi All,
Firstly  tamerj1 thank you for your solution!
And @KW123 ,as I understand it, is that how your dataset is structured, and then you want to ask for the sales of the people for each month to be sorted is that right? 

Below is the dataset I created modelled after your example data data.

vxingshenmsft_0-1726033758551.png

Then we sort by each month and each month's sales.

RankPerMonth = 
 RANKX(
    FILTER(
        ALL('Table'),
        'Table'[Month  ]=MAX('Table'[Month  ])),
        CALCULATE(
            SUM('Table'[ $  Sold  ])),,DESC)

vxingshenmsft_1-1726033863125.png

I hope my answer can solve your problem, if you still have more recent asynchronous needs, you can contact me at any time, I will be the first time to reply after receiving the message!

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

 

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

Hi @Anonymous 
Thank you for your solution. 
I'm not in a place to answer on behalf of the requester @KW123. However, I think the requirements are a little bit different than what you have kindly proposed. Attached sample file explains my solution which seems to fully address the requirements.

1.png

 

$Sold New Measure = 
VAR T1 =
    SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
    COUNTROWS ( T1 )
VAR CurrentPlacing =
    MAX ( Placing[Value] )
VAR Result =
    IF (
        CurrentPlacing <= NameCount,
        MAXX (
            TOPN (
                1,
                TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
                [@Sold], ASC,
                'Table'[Name], DESC
            ),
            [@Sold]
        )
    )
RETURN
    Result
Name Measure = 
VAR T1 =
    SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
    COUNTROWS ( T1 )
VAR CurrentPlacing =
    MAX ( Placing[Value] )
VAR Result =
    IF (
        CurrentPlacing <= NameCount,
        MAXX (
            TOPN (
                1,
                TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
                [@Sold], ASC,
                'Table'[Name], DESC
            ),
        'Table'[Name]
        )
    )
RETURN
    Result
Month Measure = 
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( 'Table'[Month] ) )
Placing Measure = 
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( Placing[Value] ) )

 

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi All,
Firstly  tamerj1 thank you for your solution!
And @KW123 ,as I understand it, is that how your dataset is structured, and then you want to ask for the sales of the people for each month to be sorted is that right? 

Below is the dataset I created modelled after your example data data.

vxingshenmsft_0-1726033758551.png

Then we sort by each month and each month's sales.

RankPerMonth = 
 RANKX(
    FILTER(
        ALL('Table'),
        'Table'[Month  ]=MAX('Table'[Month  ])),
        CALCULATE(
            SUM('Table'[ $  Sold  ])),,DESC)

vxingshenmsft_1-1726033863125.png

I hope my answer can solve your problem, if you still have more recent asynchronous needs, you can contact me at any time, I will be the first time to reply after receiving the message!

Hope it helps!

 

Best regards,
Community Support Team_ Tom Shen

 

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

 

 

 

Hi @Anonymous 
Thank you for your solution. 
I'm not in a place to answer on behalf of the requester @KW123. However, I think the requirements are a little bit different than what you have kindly proposed. Attached sample file explains my solution which seems to fully address the requirements.

1.png

 

$Sold New Measure = 
VAR T1 =
    SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
    COUNTROWS ( T1 )
VAR CurrentPlacing =
    MAX ( Placing[Value] )
VAR Result =
    IF (
        CurrentPlacing <= NameCount,
        MAXX (
            TOPN (
                1,
                TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
                [@Sold], ASC,
                'Table'[Name], DESC
            ),
            [@Sold]
        )
    )
RETURN
    Result
Name Measure = 
VAR T1 =
    SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
    COUNTROWS ( T1 )
VAR CurrentPlacing =
    MAX ( Placing[Value] )
VAR Result =
    IF (
        CurrentPlacing <= NameCount,
        MAXX (
            TOPN (
                1,
                TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
                [@Sold], ASC,
                'Table'[Name], DESC
            ),
        'Table'[Name]
        )
    )
RETURN
    Result
Month Measure = 
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( 'Table'[Month] ) )
Placing Measure = 
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( Placing[Value] ) )

 

 

 

tamerj1
Super User
Super User

Hi @KW123 

Create the following calculated table 

Placing = GENERATESERIES ( 1, 100, 1 )

 

Add a matrix visual. Place 'Table'[Month] in the columns and Placing[Value] in the rows. Don't panic when you see the error 😊

create the flowing measures and place them in the values of the matrix. 

Name Measure =
VAR T1 =
SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
COUNTROWS ( T1 )
VAR CurrentPlacing =
MAX ( Placing[Value] )
VAR Result =
IF (
CurrentPlacing <= NameCount,
MAXX (
TOPN (
1,
TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
[@Sold], ASC,
'Table'[Name], DESC
),
'Table'[Name]
)
)
RETURN
Result

$Sold New Measure =
VAR T1 =
SUMMARIZE ( 'Table', 'Table'[Name], "@Sold", [$Sold] )
VAR NameCount =
COUNTROWS ( T1 )
VAR CurrentPlacing =
MAX ( Placing[Value] )
VAR Result =
IF (
CurrentPlacing <= NameCount,
MAXX (
TOPN (
1,
TOPN ( CurrentPlacing, T1, [@Sold], DESC, 'Table'[Name], ASC ),
[@Sold], ASC,
'Table'[Name], DESC
),
[@Sold]
)
)
RETURN
Result

Month Measure =
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( 'Table'[Month] ) )

You may also want to add the Placing

Placing Measure =
IF ( NOT ISBLANK ( [Name Measure] ), MAX ( Placing[Value] ) )

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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