Forum Discussion

BM4291's avatar
BM4291
Icon for Resolver I rankResolver I
7 years ago

Find X best performing area

Hi,

 

Struggling with something at the moment and having scoured the web I keep finding myself going over the same articles and not getting any closer to where I would like to be... Maybe searching for the wrong things!

 

In short, I want to know the following.

  1. Top/Bottom performing area - I have this sorted and have followed the steps here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Top-1-per-category/m-p/225700
  2. Top/Bottom performing area excluding some i.e. I don't want one or two areas to be included in the calculation.
  3. 2nd/3rd/4th/Xth best performing area i.e. a dynamic calculation to tell me who is Xth best performing

 

I've tried using a modified version of the formula in 1 using RANKX but it's returning an unexpected result.

 

Can't share my data unfortunately but anonymised and simplified below:

 

 

The data table, call it Table1 is joined to a Team and Date dimension, Team is structured as below:

 

ID | Team | Area
1 | T1 | S1
2 | T2| S1
3 | T1 | S2

4 | T1 | S3

 

etc... For this we're just interested in the Area, not the individual teams within it.

 

Currently using the below measures in PBI

 

Staff = DISTINCTCOUNT(Table1[ID])

StaffB1 = CALCULATE([Staff], Table1[Band] = 1)

StaffB2 = CALCULATE([Staff], Table1[Band] = 2)

StaffB1B2 = [StaffB1] + [StaffB2] ... Would StaffB1B2 = CALCULATE([Staff], Table1[Band] = 1 || Table1[Band] = 2) be more performant?

%StaffB1B2 = DIVIDE([StaffB1B2], [Staff], 0)

%StaffB1B2Rank = RANKX(ALL(Teams), [%StaffB1B2])

%StaffB1B2BestArea = CALCULATE(
    LASTNONBLANK (Team[Area], 1),
    FILTER (
        TOPN(1, VALUES(Team[Area]), [%StaffB1B2], DESC), TRUE()
        )
)

%StaffB1B2BestAreaValue = CALCULATE (
[%StaffB1B2],
FILTER ( TOPN ( 1, VALUES ( Team[Area] ), [%StaffB1B2], DESC ), TRUE () )

 

When I filter this data to the latest month (as in the screenshot), I get S3 showing as top which whilst strictly true, it's a bit of an anomaly, it shouldn't be counted in the calculations, along with a few others and what I can't get my head around is how to exclude this, or focus on the 2nd best if it (or one of the others is 1st placed)... Any ideas at all?

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi BM4291,

     

    I'd like some sample data with expected result for test and coding formula, it is hard to coding formula from snapshot.

     

    Notice: some of fake data with same data structure and relationship.

     

    Regards,

    Xiaoxin Sheng

    • BM4291's avatar
      BM4291
      Icon for Resolver I rankResolver I

      Anonymous does the below help?

       

       

      TeamIDDateIDBand
      101/10/20181231
      201/10/20183212
      101/10/20184561
      101/09/20181232
      201/08/20183211
      301/10/20184561
      301/10/20187893
      301/09/20184563
      301/08/20184561
      301/10/20187891

      This table is then joined to a standard Date Dimension and a team table that looks like the below:

       

      IDTeamArea
      1T1S1
      2T2S1
      3T1S2
      4T1S3

       

      Hopefully this is a bit more helpful, let me know if you need anything else.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi BM4291,

         

        You measure seems not works on sample data, I try to write '1+2 percent' and 'Top area' measure and it works on my side. 

         

        Maybe you can take a look at following measures:

        1+2 percent = 
        DIVIDE (
            CALCULATE ( DISTINCTCOUNT ( Table1[ID] ), Table1[Band] IN { 1, 2 } ),
            CALCULATE ( DISTINCTCOUNT ( Table1[ID] ), ALLSELECTED ( Table1 ) ),
            -1
        )
        
        Top Area = 
        VAR currArea =
            SELECTEDVALUE ( Table2[Area] )
        VAR temp =
            TOPN (
                1,
                ADDCOLUMNS ( ALLSELECTED ( Table2[Area] ), "Percent", [1+2 percent] ),
                [Percent], DESC
            )
        RETURN
            IF ( CONTAINS ( temp, Table2[Area], currArea ), "Y" )
        

         

        Regards,

        Xiaoxin Sheng