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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
abbaig63
New Member

Calculate the sum of rankx values within a category, across all categories

Hello,

 

I am trying to rank a list of stores by sales on a period by period basis. For example, this is what a desired table would look like:

PeriodStoreSalesRank
1A1002
1B1501
1C753
2A1103
2B1202
2C1351

 

Then I would like have the sum of the ranks for each store like so:

StoreSum of Rank
A5
B3
C4

 

I am able to calculate the ranks in the first table using the following measure:

Rank = 

    RANKX(

        FILTER(

            ALL(Table[Period], Table[Store])

            Table[Period] = MAX(Table[Period])

        ),

        CALCULATE(SUM(Table[Sales])

    )
 
However, this requires the period being included, which I do not need, since I only care about the final sum.
How can I apply this measure across all periods independently?
 
Thank you
 
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure what is your desired outcome, but I tried to create it by using measures.

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Jihwan_Kim_0-1684811728425.png

 

Jihwan_Kim_1-1684812271405.png

 

 

Expected result measure: =
VAR _rank =
    ADDCOLUMNS (
        VALUES ( Period[Period] ),
        "@rank",
            RANK (
                SKIP,
                SUMMARIZE ( ALL ( Data ), Store[Store], Period[Period] ),
                ORDERBY ( CALCULATE ( SUM ( Data[Sales] ) ), DESC ),
                PARTITIONBY ( Period[Period] )
            )
    )
RETURN
    SUMX ( _rank, [@rank] )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure what is your desired outcome, but I tried to create it by using measures.

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Jihwan_Kim_0-1684811728425.png

 

Jihwan_Kim_1-1684812271405.png

 

 

Expected result measure: =
VAR _rank =
    ADDCOLUMNS (
        VALUES ( Period[Period] ),
        "@rank",
            RANK (
                SKIP,
                SUMMARIZE ( ALL ( Data ), Store[Store], Period[Period] ),
                ORDERBY ( CALCULATE ( SUM ( Data[Sales] ) ), DESC ),
                PARTITIONBY ( Period[Period] )
            )
    )
RETURN
    SUMX ( _rank, [@rank] )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


This works perfectly, thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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