Forum Discussion

Dog's avatar
Dog
Icon for Responsive Resident rankResponsive Resident
9 years ago
Solved

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 su...
  • Dog's avatar
    9 years ago

    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