Excel – Filter rows based on starting string, read number from filtered rows and perform arithmetic operation to generate column summary

microsoft excelmicrosoft-excel-365worksheet-function

I am having a Project and resource allocation report. I need help in generating the formula to display summary in the bottom section of my report.

Here're the specifications of my report:

  • Column A from Row 2 to Row 15 represents the Resource (persons) allocated for each project

  • Column B, Column C…. represents the percentage of resource allocated in each project per month

  • Each resource of column A is merged into 2 cells because each resource can either work in 1 or 2 project per month

  • Resource working on single project in a month will have both the cells merged . Resource working on 2 projects will have 2 rows representing the project

  • Against each project there is number representing the percentage of that resource allocated to the project

Here's the screenshot of my report:

Project and resource allocation report screenshot

At the bottom report I am having summary section which represents the count of resources allocated per project. Currently these counts are manually added by me. I need help in generating the formula for these summary. Here's what I am trying to achieve:

  1. Read string from cells (A20 – A24)
  2. Do a lookup in the month column (B2 – B15) to get the cells starting with project string
  3. Filter the numbers from the above cells (from step 2)
  4. Do summation of the numbers and divide by 100 to get the resource count

So far I am able to generate this formula which reads the number from the row passed to it:

=TEXTJOIN("",TRUE,IFERROR((MID(B2,ROW(INDIRECT("1:"&LEN(B2))),1)*1),""))

which gives me number 50 from cell B2 containing "Project A 50%" text.

Best Answer

If you have O365, you can use the FILTER function:

  • Filter the list by the contents of A20:Ann

  • Return just the last space separated value in each string (the percentage)

  • Sum the results

  • Use IFERROR in case the project doesn't exist

      =IFERROR(SUM(--((TRIM(RIGHT(SUBSTITUTE(FILTER(B$2:B$15,ISNUMBER(SEARCH($A20,B$2:B$15)))," ",REPT(" ",99)),99))))),"")
    

or (depending on whether you want to return zero or "" for a non-existent entry)

    =IFERROR(SUM(--((TRIM(RIGHT(SUBSTITUTE(FILTER(B$2:B$15,ISNUMBER(SEARCH($A20,B$2:B$15)))," ",REPT(" ",99)),99))))),"")

Edit: in the comments, the OP mentions that Projects can be similarly named but be prepended by a character, and these should be treated separately. This requires a different Filter criteria:

=IFERROR(SUM(--((TRIM(RIGHT(SUBSTITUTE(FILTER(B$2:B$15,LEFT(B$2:B$15,LEN($A20))=$A20)," ",REPT(" ",99)),99))))),"")

enter image description here

Related Question