Home » excel » excel – Sum of last 4 results in a column with multiple conditions

excel – Sum of last 4 results in a column with multiple conditions

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a list of data (top to bottom with gaps) in range AM4:AM1000 which is always added to and to which i want to find and sum the last 4 results. But I only want to find those results which correspond to a separate column, range AL4:AL1000 that is equal to cell E3, and where a third column (AS4:AS1000) meets the criteria of “p”.
Im using the code below which extracts the last 4 results but I can’t make it meet the other two conditions. any help would be gratefully appreciated

=SUM(INDIRECT("Am" & LARGE(IF(NOT(AM4:AM1000=""),ROW(AM4:AM1000),0),1) & ":Am" & LARGE(IF(NOT(AM4:AM1000=""),ROW(AM4:AM1000),0),4)))

Iv also tried the code below but this only returns the value 0

 =SUM(IFERROR(INDEX($AM$4:$AM$1000,LARGE(IF(ISNUMBER(MATCH($AL$4:$AL$1000, $E$3, 0)),IF(AS$4:AS$1000="p",MATCH(ROW(AL$4:AL$1000), ROW(AL$4:AL$1000)), "")), ROWS($I$6:$I7))),""))
How to&Answers:

Here’s an array formula for you to try – make sure to enter it by using Ctrl+Shift+Enter:

=SUMPRODUCT(IF(ROW($AM$4:$AM$1000)=TRANSPOSE(LARGE(IF(--($AL$4:$AL$1000=$E$3)*(--($AS$4:$AS$1000="p")),ROW($AM$4:$AM$1000),0),ROW($A$1:$A$4))),$AM$4:$AM$1000,0))

The result of 26 matches your criteria (highlighted cells):

enter image description here