Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
thanhphongle
Creator II
Creator II

sum(aggr(x), y) with if(z)

Hello Community

these is my table

contract_nocontract_termcontract_term_type
1360
161
162
2480
2121
262
3360
361
362

contract_nofi_acquisition
130000
29000
32000

I want to calculate the weighted average of the contract term where contract_term_type > 0. The weighting should refere to fi_acquisiton

What I tried so far is

if(contract_term_type>0, Sum(Aggr(sum(cost_asquisition/Sum(TOTAL cost_acquisition)*contract_term),contract_no)))

Unfortunetly is does not work

Hope someone can help me.

And is there a way to solve it with Set Analysis Function?

12 Replies
thanhphongle
Creator II
Creator II
Author

This is what the expression should return

1. sum(TOTAL fi_acquisition) = 41.000

2. sum(fi_acquisition)/sum(TOTAL fi_acquisition) per contract_no where contract_term_type >0

  • contract_no = 1 AND contract_term_type = 1 AND contract_term = 6 ->  30.000/41.000 = 0,7317
  • contract_no = 1 AND contract_term_type = 2 AND contract_term = 6 ->  30.000/41.000 = 0,7317
  • contract_no = 2 AND contract_term_type = 1 AND contract_term = 6 ->  9.000/41.000 = 0,2195
  • contract_no = 2 AND contract_term_type = 2 AND contract_term = 6 ->  9.000/41.000 = 0,2195
  • contract_no = 3 AND contract_term_type = 1 AND contract_term = 6 ->  2.000/41.000 = 0,0487
  • contract_no = 3 AND contract_term_type = 2 AND contract_term = 6 ->  2.000/41.000 = 0,0487

3. now take the result and multiply it with the contract_term -> Result* contract_term

  • 0,7317 * 6 = 4,39
  • 0,7317 * 6 = 4,39
  • 0,2195 * 12 = 2,63
  • 0,2195 * 6 = 1,31
  • 0,0487 * 6 = 0,29
  • 0,0487 * 6 = 0,29

4. Take the sum
4,39 + 4,39 + 2,63 + 1,31 +0,29 + 0,29 = 13,31

sunny_talwar

Try this

=Sum(Aggr(Sum({<contract_term_type = {'>0'}>}contract_term*fi_acquisition), contract_no))/Sum(fi_acquisition)

thanhphongle
Creator II
Creator II
Author

IT WORKS !!! THANKS VERY MUCH !!