Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Weighted Reimbursement Formula

I'm trying to get a weighted reimbursement formula from an Excel file to work.     Reimbursement=(Location Reimbursement/Sum of all locations reimbursements)*Total Vendor Reimbursement Here is...
  • Cmcmahan's avatar
    Cmcmahan
    7 years ago

    Ah, so since other Locations can borrow against each other under the same vendor, the expression becomes simpler:

    Reimbursement = IF(SUM('Table'[adjustments])+SUM('Table[allowance]) > 0, 0, SUM('Table'[adjustments])+SUM('Table'[allowance]) ) )

     

    This has the issue of letting vendors "borrow" against each other in the same way for the grand total, but we can fix that by combining it with the original solution and grouping at the Vendor level.  I've also added in a *-1 here because your examples have reimbursement as a positive value.

    Reimbursement = SUMX( VALUES('Table'[Vendor]), CALCULATE(IF(SUM('Table'[adjustments])+SUM('Table'[allowance]) > 0, 0, (SUM('Table'[adjustments])+SUM('Table'[allowance]))*-1 )) ) 

     

    Now we start getting really tricky in order to get the weighted reimbursement in the same measure that calculates the correct amount at the Vendor level or higher.  Luckily, we already have a working [Reimbursement] measure, so we're going to re-use that.  I use DIVIDE instead of the normal division symbol here because it seems likely that the sum of adjustments can be zero, which causes errors. DIVIDE handles division by zero errors much more gracefully than the / symbol does.

    Weighted Reimbursement = DIVIDE(SUM('Table'[Adjustments]) * CALCULATE([Reimbursement], ALLSELECTED('Table'[Location])), CALCULATE( SUM('Table'[Adjustments]), ALLSELECTED('Table'[Location])))

    And with that, I'm able to create the following matrix:

     

    If you have any questions, feel free to follow up here.