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
Dog
Responsive Resident
Responsive Resident

Display Ranked Totals

Hi All, 

 

I'm having some issues trying to retrieve a total value for items that are ranked. 

 

on my report page I have a numerical slicer which shows the top x summed sales by office. 

the sum of sales is displayed using a bar graph. 

I am using RANKX to determine the rank number on the selected office locations and this is all working perfectly. 

what my client would like to see is the total sum of Sales for the offices that appear in the bar graph , so the sum of the sales for the top 10 locations.

they would also like to see the sum of the other locations. 

 

the bit I am struggling with is the rankx function is performed on the office locations, which is possible because these make up the axis on the bar graph. However, when I try to retrieve the sum of these to display in a single measure I am unable due to the office locations not being filtered within the card. 

 

My RANKX measure is simply doing this. 

SalesRanks:=RANKX ( FILTER ( ALLSELECTED ( Office[Location Title] ), CALCULATE(SumOfSalesYTD] )), CALCULATE(SumOfSalesYTD] ),, ASC, DENSE )

 

any help would be appreciated. 

 

1 ACCEPTED SOLUTION
Dog
Responsive Resident
Responsive Resident

Looks like I've found a way to do this. 

I'll post just in case someone can think of a more straight forward way or has the same problem. 

 

in a nutshell, I calculate the table using summarize, filter this down and then perform the ranking and summing of sales using add columns. 

I wrap this all in a SUMX to interate through values and return the result. 

 

testtableoutput :=
VAR SelectedNo =
     IF (
          ISFILTERED ( 'TopN Options'[TopN] ),
          VALUES ( 'TopN Options'[TopN] ),
          BLANK ()
     )
VAR fTable =
     IF (
          ISBLANK ( SelectedNo ),
          CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
          SUMX (
               FILTER (
                    ADDCOLUMNS (
                         SUMMARIZE ( ALLSELECTED ( Office ), Office[DWHId], Office[Location Title] ),
                         "MyValue", CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
                         "MyRank", RANKX (
                              ALLSELECTED ( Office ),
                              CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
                         ,
                         DESC,
                              DENSE
                    )
               ),
               [MyRank] <= SelectedNo
          ),
          [MyValue]
     )
)
RETURN
fTable

View solution in original post

1 REPLY 1
Dog
Responsive Resident
Responsive Resident

Looks like I've found a way to do this. 

I'll post just in case someone can think of a more straight forward way or has the same problem. 

 

in a nutshell, I calculate the table using summarize, filter this down and then perform the ranking and summing of sales using add columns. 

I wrap this all in a SUMX to interate through values and return the result. 

 

testtableoutput :=
VAR SelectedNo =
     IF (
          ISFILTERED ( 'TopN Options'[TopN] ),
          VALUES ( 'TopN Options'[TopN] ),
          BLANK ()
     )
VAR fTable =
     IF (
          ISBLANK ( SelectedNo ),
          CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
          SUMX (
               FILTER (
                    ADDCOLUMNS (
                         SUMMARIZE ( ALLSELECTED ( Office ), Office[DWHId], Office[Location Title] ),
                         "MyValue", CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
                         "MyRank", RANKX (
                              ALLSELECTED ( Office ),
                              CALCULATE ( SUM ( Office[SumOfSalesYTD] ) ),
                         ,
                         DESC,
                              DENSE
                    )
               ),
               [MyRank] <= SelectedNo
          ),
          [MyValue]
     )
)
RETURN
fTable

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.