Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Calculating performance vs. target; 'left to get' versus target; performance growth in % terms

I am a new power BI user and just coming to grips with the setup. I have a large flat file loaded from excel with performance by sales rep across multiple years, multiple quarters. at a deal / transaction level.

 

I have loaded in a separate table with the targets by sales rep, by quarter.

 

I'd now like to create 3 calculations:

- Sales rep performance (sum of USD performance) versus target expressed as a percentage, for the selected QTR

- Sales rep 'left to get' versus target (i.e. target minus sum of performance) for selected QTR, but left to get cannot be less than zero i.e. if performance is greater than the target, then left to get should be zero

- Sales rep performance growth / decline in % terms versus another selected QTR

 

I think this is going to involve DAX but I'm not sure where to start.

 

Very grateful for some help.

 

Tables below are Data. Then Targets. The picture is the relationships.

 

Opportunity NameService OfferingUSD ValueRegionStageForecastFY&QSales Rep
Randomtext - 3724384903Offering 54723.23SouthWonClosedFY13 Q2John Doe 1
Randomtext - 2761410753Offering 30UKProspectedPipelineFY19 Q1John Doe 2
Randomtext - 2271928993Offering 548613NordicsQualified OutClosedFY12 Q2John Doe 3
Randomtext - 1942677260Offering 254.11NordicsWonClosedFY18 Q4John Doe 4
Randomtext - 5101192472Offering 534642.03NordicsQualified OutClosedFY13 Q4John Doe 5
Randomtext - 7975257163Offering 60SouthQualified OutClosedFY19 Q1John Doe 6
Randomtext - 5482864152Offering 5371.67SouthWonClosedFY12 Q4John Doe 6
Randomtext - 3828510690Offering 1537.12NordicsInLegalCommitFY19 Q1John Doe 7
Randomtext - 1195647477Offering 532992.41NordicsQualified OutClosedFY13 Q4John Doe 8
Randomtext - 8467719711Offering 30WestQualified OutClosedFY18 Q4John Doe 9
Randomtext - 7577179194Offering 53150MidwestWonClosedFY13 Q4John Doe 10

 

Sales RepFY18 Q1FY18 Q2FY18 Q3FY18 Q4FY19 Q1
John Doe 12100056000950009100042000
John Doe 21400095000220008600015000
John Doe 36300078000670009300074000
John Doe 44800032000620004400050000
John Doe 58700055000650001500068000
John Doe 6260008500072000100008000
John Doe 78800099000790005800045000
John Doe 83800015000390005200076000
John Doe 99100084000140007600071000
John Doe 105000061000290009400078000

8 Replies

  • v-frfei-msft's avatar
    v-frfei-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    One sample for your reference. Please check the following steps as below.

     

    1. Unpivot the Targets table, please refer to the M code in power query as below.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZG9DoMwDIRfBTEzxEn8k71TXwExVupU3n9rrFxUqKcThz/77Oz7+jzfn+VxvhZatzVTSqkry9DGUPg1ux7bBcvdpnovz3mooQ1xwEq3pYzfakNF0Wb6NWDVQ6C8YIpAK1L4sD+MPQy6M0IKX8P1bwuY+C7YwVCmmEYJfqDUXWRsDRSU4dd4EfOV7J6pTAxDVQLWLs9juMB8D0V2pYDR71J9dfAZ49rkx3LHFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Sales Rep" = _t, #"FY18 Q1" = _t, #"FY18 Q2" = _t, #"FY18 Q3" = _t, #"FY18 Q4" = _t, #"FY19 Q1" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Rep", type text}, {"FY18 Q1", Int64.Type}, {"FY18 Q2", Int64.Type}, {"FY18 Q3", Int64.Type}, {"FY18 Q4", Int64.Type}, {"FY19 Q1", Int64.Type}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Sales Rep"}, "Attribute", "Value")
    in
        #"Unpivoted Columns"

     

    2. We need create three calculated tables as below.

     

    Sales Rep = DISTINCT(UNION(VALUES(Data[Sales Rep]),VALUES('Targets'[Sales Rep])))
    FY = DISTINCT(UNION(VALUES(Data[FY&Q]),VALUES(Targets[Attribute])))
    another selected QTR = VALUES(FY[FY&Q])

    3. Then create relationship between tables as the pic.

     

     

    4.Afther that we can create three measures to get the results as we need.

     

    Sales rep performance = 
    CALCULATE ( SUM ( Data[USD Value] ) ) / CALCULATE ( SUM ( Targets[Value] ) )
    
    left to get = 
    VAR _data =
        CALCULATE ( SUM ( Data[USD Value] ) )
    VAR _tar =
        CALCULATE ( SUM ( Targets[Value] ) )
    VAR _min = _tar - _data
    RETURN
        IF ( _min > 0, _min / _tar, 0 )
    
    Sales rep performance growth = 
    VAR _sele =
        CALCULATE (
            SUM ( Data[USD Value] ),
            FILTER ( ALL ( Data ), 'Data'[FY&Q] = SELECTEDVALUE ( FY[FY&Q] ) ),
            VALUES ( Data[Sales Rep] )
        )
    VAR sele2 =
        CALCULATE (
            SUM ( Targets[Value] ),
            FILTER ( ALL ( Targets ), 'Targets'[Attribute] = SELECTEDVALUE ( FY[FY&Q] ) ),
            VALUES ( Targets[Sales Rep] )
        )
    RETURN
        DIVIDE ( [Sales rep performance] - _sele / sele2, _sele / sele2 )
    

     

    For more details, please check the pbix as attached.

     

    Regards,

    Frank

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks v-frfei-msft - I am still working this through and following the logic.

       

      Why did you need to create the 2 calculated tables of FY and Sales Rep? These fields already exist in 'data'. Why can't we just create a relationship between the data table and the targets table?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

         

        After unpivoting the target table, there will be duplicates appearing in the Sales rep column.  For a relationship to flow from the Sales rep column of the Data Table to the Sales rep column of the Target table, the Sales rep column of the Target table should only have unique values.  So that is the primary reason.  Furthermore, whenever, there is a Date column, there should always be  Calendar Table so that you can use Date/Time Intelligence functions.  Both the target table and the Data Table should be linked to the Calendar Table.

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-frfei-msftHi. I am working with the dummy file / your pbix, and moving info back in to my working model as I work through the components and understand them.

       

      When I bring in the 'Left to Get' calculated measure (which you helped me to create) to a table on my visualizations panel, it has the strange effect of calculating left to get for roles / reps that have been filtered out using page level filters. This forces the table to dramatically expand and include people / roles that were filtered out prior to adding in the calculated measure.

       

      I can see that the page level filters have been applied to the visual level filters, but the unwanted info still shows in the table.

       

      Is there any way to prevent this from happening?

      • v-frfei-msft's avatar
        v-frfei-msft
        Icon for Community Support rankCommunity Support

        Hi Anonymous ,

         

        Did you create correct relationships between tables? And did you add the same columns as my pbix to the visual?

         

        Regards,

        Frank