I have a Sales table (CustCode, InvDate, InvNumb, InvAmount) that links to the Commission table (CustCode, CommissPerc, EffectiveDate) via CustCode. The report is for commissions by customer, and I am trying to calculate the commission percentage by multiplying the Sales_InvAmount by the Commission_CommissPerc field. However, if the Commission table has more than 1 line per CustCode, it creates a duplicate line for each EffectiveDate.
For example, CustCode AB45 has an invoice dated 02/04/2013 for $1,000 in the Sales table. There are 3 lines in the Commission table for CustCode AB45 (CommissPerc 0.015 EffectiveDate 04/19/2012 -- CommissPerc 0.018 EffectiveDate 11/07/2012 -- and CommissPerc 0.020 EffectiveDate 02/25/2013). I would like the formula to compare the Sales_InvDate to the Commission_EffectiveDate and only return 1 line using the 11/07/2012 CommissPerc of 0.018 (because the Sales_InvDate of 02/01/2013 is AFTER Commission_EffectiveDate of 11/07/2012 but BEFORE Commission_EffectiveDate of 02/25/2013) multiplied by the Sales_InvAmount of $1,000.00 for a value of $18.00. How is the easiest way to do this?
Tony
For example, CustCode AB45 has an invoice dated 02/04/2013 for $1,000 in the Sales table. There are 3 lines in the Commission table for CustCode AB45 (CommissPerc 0.015 EffectiveDate 04/19/2012 -- CommissPerc 0.018 EffectiveDate 11/07/2012 -- and CommissPerc 0.020 EffectiveDate 02/25/2013). I would like the formula to compare the Sales_InvDate to the Commission_EffectiveDate and only return 1 line using the 11/07/2012 CommissPerc of 0.018 (because the Sales_InvDate of 02/01/2013 is AFTER Commission_EffectiveDate of 11/07/2012 but BEFORE Commission_EffectiveDate of 02/25/2013) multiplied by the Sales_InvAmount of $1,000.00 for a value of $18.00. How is the easiest way to do this?
Tony