Forum Discussion

adj87's avatar
adj87
Helper I
4 years ago
Solved

Conditional Approximate Lookups

Hi Everyone,

I could really use some help here. I have lots of experience with Excel but I am relatively new to PowerBI.

 

I have a series of performance data (sales figures for employees at various levels, Entry Level, Professional, Senior, etc.) and the plans they are tallied against those levels:

 

Sales (Entry Level)Points
$00 pts
$10005 pts
$250010 pts

 

Table above is 1 of 4 metrics for 1 of 5 job titles.

 

I currently have a table in Excel using UDFs full of Case/IFs for all this, but I want to transform that into PowerBI. My first thought was R/Python, but I am not familiar with those languages. My last straw idea is to create tables for each job title, but that almost defeats the purpose of automation since our titles do change/evolve every few years.

 

Any help/direction would be great, thanks!

  • Hi adj87 ,

     

    I think you need to create the following tables in Power BI.

    • Job - A table containing all the job names.
    • FactTable - A table containing sales and starts data.
    • Points - A table with rules for converting sales and starts to points.
    • Payment - A table with rules for converting points to payment.

     

        

      

     

    Then add the "End" columns to table Points and table Payment, indicating that the sales/starts/points data between the Values Start/Points Start and the Values End/Points End can be converted to the corresponding points/payment.

     

     

    If you import the table from Excel file in the following form, then you need to do some conversions to transform it to table Points and table Payment. Please refer to the attachment for the steps and code.

     

     

    Then create the following relationships and measures.

     

    SumSales = SUM(FactTable[Sales])
    Sales_Points = 
    CALCULATE (
        MAX ( Points[Points] ),
        FILTER (
            Points,
            Points[Category] = "Sales"
                && Points[Values Start] <= [SumSales]
                && Points[Values End] > [SumSales]
        )
    )
    Starts_Points = 
    CALCULATE (
        MAX ( Points[Points] ),
        FILTER (
            Points,
            Points[Category] = "Starts"
                && Points[Values Start] <= [SumSales]
                && Points[Values End] > [SumSales]
        )
    )
    TotalPoints = value( SUBSTITUTE( [Sales_Points], "pts", "" ) ) + value( SUBSTITUTE( [Starts_Points], "pts", "" ) )
    Payment = 
    CALCULATE (
        MAX ( Payment[Payment] ),
        FILTER (
            Payment,
            Payment[Points End] > [TotalPoints]
                && Payment[Points Start] <= [TotalPoints]
        )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

6 Replies

  • Apologies for the abiguity, you always know every facet of your data until you bring in an outside party ... Hopefully this example helps. I've pasted example data/plans here (Forgive me for the endless string of data, I didn't know any other way to send it). The idea being each employee is bonused on Sales/Starts. Those figures are then converted to "Points" and the points factor into the overall payment (among many other things). All these metrics are based on title and in some cases time in the company.

     

    (Plan to follow in second message... this message exceeds 20k characters)

     

    Thank you!

     

    YearQuarterJob TitleSalesStarts
    2020Q1Entry A48849
    2020Q1Entry A16650
    2020Q1Entry A80993
    2020Q1Entry B559813
    2020Q1Entry B413416
    2020Q1Entry B17943
    2020Q1Professional61603
    2020Q1Professional13129
    2020Q1Professional486020
    2020Q1Senior82346
    2020Q1Senior92899
    2020Q1Senior800614
    2020Q2Entry A386612
    2020Q2Entry A21884
    2020Q2Entry A775110
    2020Q2Entry B139114
    2020Q2Entry B36877
    2020Q2Entry B2035
    2020Q2Professional487715
    2020Q2Professional90246
    2020Q2Professional74071
    2020Q2Senior43197
    2020Q2Senior535420
    2020Q2Senior104918
    2020Q3Entry A774912
    2020Q3Entry A32815
    2020Q3Entry A402
    2020Q3Entry B53975
    2020Q3Entry B170512
    2020Q3Entry B749216
    2020Q3Professional589612
    2020Q3Professional39491
    2020Q3Professional444717
    2020Q3Senior666610
    2020Q3Senior914
    2020Q3Senior673011
    2020Q4Entry A34417
    2020Q4Entry A20574
    2020Q4Entry A30481
    2020Q4Entry B16465
    2020Q4Entry B396116
    2020Q4Entry B58867
    2020Q4Professional63518
    2020Q4Professional77837
    2020Q4Professional56887
    2020Q4Senior668916
    2020Q4Senior82019
    2020Q4Senior30786

     

    Entry A - Sales 
    00 pts
    10005 pts
    250010 pts
    500015 pts
    Entry B - Sales 
    00 pts
    30005 pts
    500010 pts
    750015 pts
    Professional - Sales 
    00 pts
    50005 pts
    750010 pts
    1000015 pts
    Senior - Sales 
    00 pts
    50005 pts
    750010 pts
    1000015 pts
    Entry A - Starts 
    00 pts
    2.55 pts
    510 pts
    7.515 pts
    Entry B - Starts 
    00 pts
    55 pts
    7.510 pts
    1015 pts
    Professional - Starts 
    00 pts
    55 pts
    7.510 pts
    1015 pts
    Senior - Starts 
    00 pts
    105 pts
    1510 pts
    2015 pts
    Entry A / Entry B - Points
    00
    20Payment
    Professional / Senior - Points
    00
    20Payment
    30Double Payment
    • v-kkf-msft's avatar
      v-kkf-msft
      Community Support

      Hi adj87 ,

       

      I think you need to create the following tables in Power BI.

      • Job - A table containing all the job names.
      • FactTable - A table containing sales and starts data.
      • Points - A table with rules for converting sales and starts to points.
      • Payment - A table with rules for converting points to payment.

       

          

        

       

      Then add the "End" columns to table Points and table Payment, indicating that the sales/starts/points data between the Values Start/Points Start and the Values End/Points End can be converted to the corresponding points/payment.

       

       

      If you import the table from Excel file in the following form, then you need to do some conversions to transform it to table Points and table Payment. Please refer to the attachment for the steps and code.

       

       

      Then create the following relationships and measures.

       

      SumSales = SUM(FactTable[Sales])
      Sales_Points = 
      CALCULATE (
          MAX ( Points[Points] ),
          FILTER (
              Points,
              Points[Category] = "Sales"
                  && Points[Values Start] <= [SumSales]
                  && Points[Values End] > [SumSales]
          )
      )
      Starts_Points = 
      CALCULATE (
          MAX ( Points[Points] ),
          FILTER (
              Points,
              Points[Category] = "Starts"
                  && Points[Values Start] <= [SumSales]
                  && Points[Values End] > [SumSales]
          )
      )
      TotalPoints = value( SUBSTITUTE( [Sales_Points], "pts", "" ) ) + value( SUBSTITUTE( [Starts_Points], "pts", "" ) )
      Payment = 
      CALCULATE (
          MAX ( Payment[Payment] ),
          FILTER (
              Payment,
              Payment[Points End] > [TotalPoints]
                  && Payment[Points Start] <= [TotalPoints]
          )
      )

       

      If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

      Best Regards,
      Winniz

      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

      • adj87's avatar
        adj87
        Helper I

        Thank you! This is a great help. I've applied these examples to my main workbook.

         

        Your attached/measures above for Starts_Points references "SumSales" so I added another measure "SumStarts". I adjust the attached model with this change, and everyone calculated correctly.

         

        I did notice a odd error. I fat fingered 1 of the point tables so that a Professional Recruiter would get 3 pts at the 0-11 and 0-8 ranges depending on group.

         

         

        This error caused everyone, regardless of title, to recieve at least 3 pts (I've corrected it above). Based on my limited understanding of the formulas used here, I didn't think that would occur. I assume this has something to do with the relationship linking Job Title/rest of the tables and the "order of operations" for lack of a better term (measure applied first then the relationship for example). Any light shed on this would be helpful so I can find a way to better avoid errors like this.

        Thank you!