简体   繁体   中英

Conditional SUM difficulty in Excel

I have the following problem: I need to sum the values in the three columns "Value", and at the same time calculate the discount rate for all items that are marked with the "YES" flag.

The rule for calculating the discount is as follows: For each item marked, separate the word before the "To" tab and search the "Products" table just below the main table. (See attached picture)
Comments:

  1. The construction "Fruit To ..." is standardized, it will always occur in this way;
  2. All marked items must have a corresponding line in the "Fruits" table;
  3. The two tables have different amount of rows;
    I already tried all possible combinations of matrix sum, INDEX+MATCH, VLOOKUP, SUMPRODUCT, etc. which I could imagine and could not come up with in a formula that worked.

If someone can see a way that I have not tried yet and that works, thank you in advance for any help!

Angelino

在此处输入图片说明

Try following which would sum adding discount where flag is Yes. You can amend ranges according to number of rows present in sum range and lookup range.

 {=SUMPRODUCT(C7:C17*IF($B$7:$B$17="Yes",VLOOKUP(LEFT($A$7:$A$17$,FIND(" ",$A$7:$A$17$)-1),$A$20:$B$22,2,FALSE),1)) + SUMPRODUCT(D7:D17*IF($B$7:$B$17="Yes",VLOOKUP(LEFT($A$7:$A$17$,FIND(" ",$A$7:$A$17$)-1),$A$20:$B$22,2,FALSE),1)) + SUMPRODUCT(E7:E17*IF($B$7:$B$17="Yes",VLOOKUP(LEFT($A$7:$A$17$,FIND(" ",$A$7:$A$17$)-1),$A$20:$B$22,2,FALSE),1))}

使用SUMIF作为“伪查找”来获取百分比,您可以使用此公式

=SUMPRODUCT(SUMIF(A20:A22,LEFT(A7:A17,FIND(" ",A7:A17)-1),B20:B22)*(B7:B17="Yes")*C7:E17)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM