Search code examples
excelsubsetcontainssumifs

Excel - sum if name is subset of another


Say I have a table like this in Excel (except the third and last column, which is what I want to obtain)

Name Value What I want
X 1 1
X-Y 1 2
X-Y-Z 0 2
X-V 1 2

So in column 3 I want to do a sumif which sums the column "Value" across all rows where Name is a subset of the given name in the row being looked at. E.g. for row 2 the returned value will be 2 - because both X and X-Y is a subset of X-Y - so it sums these two rows' values.

How can I do this in a formula?


Solution

  • Found the solution myself. In C2 put

    =SUMPRODUCT($B$2:$B$5; --(IFERROR(IF(FIND($A$2:$A$5;A2)>0;1;0);0)=1))