3
votes

So I have one table that has unique invoices as its rows, with a vendor name and an invoice cost among its columns, something like:

Invoice | Vendor | Cost
AAA     | Good Co| $10
BBB     | Good Co| $15
CCC     | Best Co| $30
DDD     | Bad Co | $50

And created a custom column to give me a total spend for each vendor:

VendorGrandTotal = 
CALCULATE(SUM('Raw Data'[Cost]),ALLEXCEPT('Raw Data','Raw Data'[Vendor]))

To get a result like:

Invoice | Vendor | Cost | Total
AAA     | Good Co| $10  | $25
BBB     | Good Co| $15  | $25
CCC     | Best Co| $30  | $30
DDD     | Bad Co | $50  | $50

Meanwhile I have another table that depicts percentage of rebate from the vendor based on if the total spend with them is above or below a certain amount. Something like:

Vendor   | Tier 1 % | Tier 1 From | Tier 1 To | Tier 2% | Tier 2 From
Good Co  | 1%       | $0          | $20       | 2%      | $20

...and so on.

So in the case of this example we should be getting a rebate of 2% since the total spend of the invoices with Good Co adds up to greater than $20. But I'm stumped for how to execute this automatically within Power BI. Is there a way to produce a column or table somewhere that checks that the vendor in the invoices table is the same one from the rebate tier list AND can check against the different tier levels to see what percentage the rebate is AND return that percentage as a result that other calculations can be run against?

1

1 Answers

2
votes

I'd suggest unpivoting your rebate table to look like this instead:

Vendor   | Tier | From | To  | Rebate
Good Co  | 1    | $0   | $20 | 1%
Good Co  | 2    | $20  |     | 2%

Then you can look up the appropriate rebate percent by taking the maximal matching row where VendorGrandTotal is greater than From.

As a calculated column on 'Raw Data', you can do this:

Rebate % = 
MAXX(
    FILTER(Rebates,
        Rebates[Vendor] = EARLIER([Vendor]) &&
        Rebates[From] < EARLIER([VendorGrandTotal])
    ),
    Rebates[Rebate]
)