Solved

Excel formula to pull only certain text from row in CountIf

Posted on 2014-10-24
7
270 Views
Last Modified: 2014-10-24
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.
0
Comment
Question by:Katharina DuBose
  • 4
  • 3
7 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
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
0
 

Author Comment

by:Katharina DuBose
Comment Utility
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.
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
Comment Utility
Here's the revised formula to handle any number of digits:
=COUNTIF(INDIRECT("'" & SUBSTITUTE(SUBSTITUTE(LEFT(A4,FIND("-",A4)-1),"[",""),"]","") & "'!A1:A500" ),MID(A4,FIND("-",A4,FIND("-",A4)+1)+1,10))

See example workbook.

-Glenn
EE-countif.xlsx
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Katharina DuBose
Comment Utility
I guess my copy is not working but it's working in the example.  I'll figure that out, perfect!  Thank you so much!
0
 

Author Closing Comment

by:Katharina DuBose
Comment Utility
Thank you!
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
Just check your cell references (A4 in the example) and make sure they're lining up with your PivotTable data.
0
 

Author Comment

by:Katharina DuBose
Comment Utility
ok, thank you
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now