Link to home
Start Free TrialLog in
Avatar of Katharina DuBose
Katharina DuBose

asked on

Excel formula to pull only certain text from row in CountIf

I am trying to wrap my head around this and hoping you can help.

I have a workbook that has a pivot table that looks like this:

1.  Sheet 'Metrics'
     -  Column A contains Data that looks similar to this:                        
        [Accounting Export]-Bug-9923      
        [Accounting Export]-Bug-9937                        
        [Accounting Export]-User Story-2585

2.  Sheet      'Accounting Export' (no brackets) is created
     - Column A contains the id's 9923, 9937 etc.  There may be multiple columns with this data

3.  Back on the 'Metrics' sheet
     - Column B contains a CountIf.  The CountIf is to count all rows on the Accounting Export sheet that contain the ID.  So for our example; Give me a count of all the rows in column A of the Accounting Export sheet that contain 9923.  

   - I would like this count if formula to automatically look at the data in column A -  [Accounting Export]-Bug-9923 and use the text before the front hyphen (Accounting Export sheet (minus the brackets) to find the sheet to look in and after the last hyphen to find the id (9923).  There will always be brackets around the product to ignore and the number will always be after the last hyphen.

I was given something like:  COUNTIF(INDIRECT("'" & LEFT(A4,FIND("-",A4)-1) & "'!A1:A500" ),MID(A4,FIND("-",A4)+1,4)) but I can't seem to understand it enough to altar the way I need.
Avatar of Glenn Ray
Glenn Ray
Flag of United States of America image

There are two issues.

First, the formula does not remove the square brackets from the string, so it's trying to look at a sheet named [Accounting Export].  Second, the function is not returning the rightmost digits after the second hyphen to add to the COUNTIF; it's getting the four after the first hyphen (ex., "Bug-").

If the IDs are always four digits, then this formula should return the correct value:
=COUNTIF(INDIRECT("'" & SUBSTITUTE(SUBSTITUTE(LEFT(A4,FIND("-",A4)-1),"[",""),"]","") & "'!A1:A500" ),RIGHT(A4,4))

-Glenn
Avatar of Katharina DuBose
Katharina DuBose

ASKER

I can't seem to get it to register in the query.  The numbers will not always be 4 digit - they can range up to 6.  I tried with 4 digits and it fills the cell with the #VALUE!.  I've attached a file as an example.
ASKER CERTIFIED SOLUTION
Avatar of Glenn Ray
Glenn Ray
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess my copy is not working but it's working in the example.  I'll figure that out, perfect!  Thank you so much!
Thank you!
Just check your cell references (A4 in the example) and make sure they're lining up with your PivotTable data.
ok, thank you