Forum Discussion

VikKos's avatar
VikKos
Regular Visitor
4 years ago
Solved

How to make calculation for each column individually by using Measures

Hello!

I have the list of SalesReps that have taken advance payments for their job and those that didn’t

After some time, they have a commission earned, which need to be paid.

I need to deduct parts of the advanced payment according to specific rules for those SalesReps that took advance payment. I need to calculate each person individually and show total amount to be paid in the PowerBI report

Report model is quite complex and I cannot do these calculations in calculated columns as long as it leads to the error of circular reference. However when I try to do it with the measures total amount is incorrect, as long as the formula deducts advance payment for all amount of all SalesRep (even for those that didn’t take advance payments)

Does anyone know how to make a measure that would calculate each person individually and sum up the results later.

I’ll be very grateful for your advise how to make this measure in correct way.

 

Current formula:

_To be paid in December INCORRECT = VAR PlannedPayment = SUMX('Commission',Commission[_Total commission])*0.2

VAR Half_of_PlannedPayment = SUMX(Commission,Commission[_Total commission])*0.1

VAR AdvPayment = SUMX('Advance Payments','Advance Payments'[Advance payment])

RETURN

IF(AdvPayment>Half_of_PlannedPayment,Half_of_PlannedPayment,PlannedPayment-AdvPayment)

 

Data:

 

SalesRepAdvance payment
Bob25000
Andy10000
Peter15000
John4000
James9000
Mary0
Tim0
Alex0

 

SalesRepCustomer NameOrder number_Total commission
BobCustomer1380206432514 162
AndyCustomer238020651134 145
PeterCustomer3380206505521 530
JohnCustomer438020650546 703
JamesCustomer5380206489724 156
JamesCustomer638020630887 285
JamesCustomer738020633291 530
MaryCustomer8380206371515 779
MaryCustomer938020645239 857
TimCustomer10380206377612 568
TimCustomer1138020637172 515
AlexCustomer1238020633502 986
AlexCustomer1338020639183 511

 

Relationship via SalesRep 1 to Many

  • VikKos  okay let's try this 

     

    Measure =
    SUMX (
        'Advance Payments',
        VAR AdvPayment = 'Advance Payments'[Advance payment]
        VAR PlannedPayment =
            SUMX ( RELATEDTABLE ( 'Commission' ), Commission[_Total commission] ) * 0.2
        VAR Half_of_PlannedPayment =
            SUMX ( RELATEDTABLE ( 'Commission' ), Commission[_Total commission] ) * 0.1
        RETURN
            IF (
                AdvPayment > Half_of_PlannedPayment,
                Half_of_PlannedPayment,
                PlannedPayment - AdvPayment
            )
    )
    

     

    pbix is attached

     

     

     

4 Replies

  • smpa01's avatar
    smpa01
    Community Champion

    VikKos  the measure is producing this. What are you expecting and why?

     

     

    • VikKos's avatar
      VikKos
      Regular Visitor

      Hi smpa01 

      Total amount is supposed to be 17 394, instead of 12 673. As long as advanced payment for 3 SalesReps should not be deducted. Current table shows correct values for the rows, but incorrect total. Only in case calculated column is used I can get this correct Total amount.

      Thank you!

  • smpa01's avatar
    smpa01
    Community Champion

    VikKos  okay let's try this 

     

    Measure =
    SUMX (
        'Advance Payments',
        VAR AdvPayment = 'Advance Payments'[Advance payment]
        VAR PlannedPayment =
            SUMX ( RELATEDTABLE ( 'Commission' ), Commission[_Total commission] ) * 0.2
        VAR Half_of_PlannedPayment =
            SUMX ( RELATEDTABLE ( 'Commission' ), Commission[_Total commission] ) * 0.1
        RETURN
            IF (
                AdvPayment > Half_of_PlannedPayment,
                Half_of_PlannedPayment,
                PlannedPayment - AdvPayment
            )
    )
    

     

    pbix is attached