Formula to Retrieve Multiple Column Numbers in Which a Value Appears - excel

I am trying to use an on sheet formula that will provide me with all the column numbers in which a value exists. For the sake of example: I want to find all the columns on Sheet1 that have a value of ThisHeader in Row1.
I have been able to use the below formula to retrieve the result I want if the value I'm searching for only appears one time:
=MATCH("ThisHeader",1:1,0)
I'm unsure how to implement this same logic, but give me multiple column numbers if ThisHeader exists in multiple columns.
I'm not particular about how the result is displayed, although ideally I'd use something like: =SUBSTITUTE(ADDRESS(1,col_number,4),"1","") after the column numbers are retrieved in order to translate to a letter format. perhaps with a comma or dash separating each number/column letter. I could add or use multiple formulas and columns rather than a nested formula as well if that is the best or only route.
Thanks in advance!

If you have O365, you can use:
=AGGREGATE(15,6,1/($1:$1="ThisHeader")*COLUMN($1:$1),SEQUENCE(COUNTIF($1:$1,"ThisHeader")))
If you do not have the SEQUENCE function, you can replace it and use:
=AGGREGATE(15,6,1/($1:$1="ThisHeader")*COLUMN($1:$1),ROW(INDEX($A:$A,1):INDEX($A:$A,COUNTIF($1:$1,"ThisHeader"))))
Results
The formula returns an array of the column numbers. So, to visualize them if you don't have the dynamic array feature of recent Excel versions, you may have to enter this as an array formula (with ctrl+shift+enter over multiple cells. Or by using an INDEX function to return each element.

Related

Automatic Excel Formula instead of writing by hand

Im trying to count the duplicated values between the 2 row so im using the formula as you can see it in the image =SUM(COUNTIFS(E4:S4,{"1","2","3"}))
so I have to write the numbers so I dont want write the numbers I want select the cells instead, any formula would do that? I already searched and tried many things but nothing seem to work
Put those values in cells - and refer to those cells as condition.
Next level: insert those values in a table, that you eg. call FilterBy and the column values
Then you can us this formula:
=SUM(COUNTIFS(E4:S4,filterBy[Values]))
Hat I don't understand: why are you using SUM - like this, it doesn't make sense, as COUNTIFS returns one value.
If you want to some all filtered values then you need this formula:
=SUM(SUMIFS(E4:S4,E4:S4,filterBy[Values]))

Excel CountIfs with an or condition on Dates

Looking to try and find the following in Excel but am having issues getting this to work.
I have Dates in Column A which need to be checked against Dates in the Query Column to compare. I want to count all records where the comparison column is greater than the date in A5 or is an empty cell. There are other conditions that I will also want to check but cannot seem to get this to work.
=COUNTIFS(Query1[Purchased Date],OR(Query1[Purchased Date]="",Query1[Purchased Date]>A5))
use:
=SUMPRODUCT(--((Query1[Purchased Date]="")+(Query1[Purchased Date]>A5)>0))
You can use an array function instead of countif.
Suppose your dates are in the range A2:A25 and your reference date is in cell B2.
If you type in any other cell
=SUM((A2:A25>B2)+(A2:A25=""))
and hit Ctrl+Shift+Enter it will give you the count you want.
This happens because Excel will resolve the first inner parentheses (A2:A25>B2) as an array of TRUE/FALSE, and does the same to the second (A2:A25=""). Next it will sum them, which is equivalent to the OR operation, and yields as a result an array of zeros (FALSE) and ones (TRUE). It wraps up by summing this array (with the function sum), all in one cell.
Perhaps this is more of a comment than an answer, but in this particular case you can just add the two separate totals:
=COUNTIF(Query1[Purchased Date],"")+COUNTIF(Query1[Purchased Date],">"&A5)
because the conditions are mutually exclusive.
Whether this helps or not depends on what additional criteria you want to add.
BTW there are two issues with your original formula:
(1) If you are combining lists of values with OR logic, you have to use addition instead (as in the two answers which use Sum or Sumproduct).
(2) The syntax of a Countif or Countifs where the range has to be kept separate from the criteria won't let you do what you want to do, so this again leads you to Sum or Sumproduct.

EXCEL: How can I check for a keyword in a string, compare it to a range and return the corresponding value in that range?

I need to categorize data: I have a column with the description of the element I'm interested in. I want to check that description for a keyword, then check if that keyword is contained in for example column A of a separate table. If a match is found, I need returned the value in the next column (in this example column B) of the same separate table.
The attached screenshot shows how the data is organized. The column called Column1 is the output I need.
I have actually found a solution, but it involves lots of nesting, I need to force the categories and keywords in the formula and I can't add all the conditions I need; this is the current formula:
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);"OTHER")
And for more categories I repeat the formula instead of "OTHER":
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);IFERROR(IF(SEARCH("keyword2";cellWithDescription2);"category2";);"OTHER"))
which is not ideal, especially with many categories. How can I accomplish the same task with a simpler and more efficient formula, possibly comparing the keyword to values in a table (and not inside the formula itself, as I did now)?
Thanks in advance for your help!
This works for me
=INDEX(category,MATCH(1,--ISNUMBER(SEARCH(keyword,cellWithDescription)),0),1)
enter as array formula, thus ctrl+shift+enter after copying the formula (curly brackets will appear around the formula)

COUNTIFS with unique values Excel

I am trying to produce a count of the number of times different strings come up in an Excel table. An example table, currently in SHEET1, would be this:
I have another table in another spreadsheet where I want to indicate, for each letter on the left in Table 1, how many entries for "za", "zc" or "zd" come up on the right. However, I would only like to only consider one entry of each.
The end result, on row B of SHEET2, would have to be something like this:
At the moment I am using a combination of SUM and COUNTIFS to do the job.
More specifically, applied to the example, I am using the following formula:
=SUM(COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
The formula is doing some of what is intended. However, it is not counting each entry just one time. Instead, its is counting, for each letter on the left, every entry of "za","zc" or "zd". The table that the formula is returning is as follows:
How can I change the formula so that it does what I intend?
Thank you.
My initial thought would be:
=SUM(MIN (1,COUNTIFS(Sheet1!A1:A18,Sheet2!$A1,Sheet1!B1:B18,{"za","zc","zd"}))
but I’m not where I can test if the MIN will apply properly to the COUNTIFS array of results. ;-)
EDITED: The MIN function is taking minimum of 1 or all of the items in the COUNTIFS array, rather than minimum of 1 and each item in the COUNTIFS array, which is what I was afraid of. Using
=MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"za"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zc"),1)+MIN(COUNTIFS(Sheet1!A$1:A$18,Sheet2!$A1,Sheet1!B$1:B$18,"zd"),1)
will gain the desired results. It is a little clunky, but simpler than an array formula. If you want an array formula, you can use:
=SUM(FREQUENCY(IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),""),IFERROR(MATCH({"za","zc","zd"},(IF(Sheet1!$A$1:$A$18=$A5,Sheet1!$B$1:$B$18)),0),"")))
This uses the FREQUENCY function to take a set of values and see how many items in another set of values fall within each of the data ranges. Since you need text instead of numbers, we use the MATCH function to find out the first time the value occurs in your list, returning "" with the IFERROR function if it doesn't. (We only need the first occurrence since you don't want to know how many occurrences there are). Since it is text, we use the same input for both arguments for FREQUENCY.
Therefore, if you need to change the values you are looking for or the ranges in which you are searching, make sure to change both! Alternately, you could list the values out somewhere, say in F1:F3, and make a named range for this, another one for A1:A18, and another for B1:B18. Your formula would then look something like this:
=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))
Then you need only change your named range definitions and your formulas would update. :-)
NOTE: Since this is an array formula, you must close out of the cell by pressing CTRL+SHIFT+ENTER rather than only ENTER. When you look at the formula bar, you should see
{=SUM(FREQUENCY(IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),""),IFERROR(MATCH(SearchValues,(IF(colA=$A2,colB)),0),"")))}
It does NOT work to enter the curly braces yourself. ;-)
You can use this formula at B1 and fill down:
B1:
=SUMPRODUCT(((Sheet1!$A$1:$A$18=A1)*(Sheet1!$B$1:$B$18= {"za","zc","zd"}))/
COUNTIFS(Sheet1!$A$1:$A$18,Sheet1!$A$1:$A$18,Sheet1!$B$1:$B$18,Sheet1!$B$1:$B$18))

#REF error when using INDEX function

I cannot understand why everytime I use INDEX in excel to find a value given the two criteria, I get a #REF error.
INDEX(C2:L1048576,MATCH(O1,A2:A1048576,0),MATCH(O2,B2:B1048576,0))
There were no deleted cells, nor were they shifted at any point in time. They have the same number of rows too. The arrays to search into are correct.
Thanks. I would appreciate if anyone can give me some guidance. I am new to the INDEX formula.
The formula you're using doesn't find a value according to two criteria. The comments you were given explain what you're actually doing.
INDEX returns one cell value from a given range, according to a row and column index - the location within your range, starting with 1. (If your reference has only one row or column, one of them can be omitted).
MATCH finds a value in a range and returns its index.
So finding one value in a one-dimension range is easy using these two functions, using something like this (with a range of one column and multiple rows) =INDEX(range,MATCH(value,range,0),1).
To find two criteria you need to tweak this concept. One way is to use concatenation of strings, using the & operator, and for this you'll also need to use an array formula (entering it using Ctrl+Shift+Enter) like this formula:
=INDEX($C$2:$C$1048576,MATCH(O1&O2,$A$2:$A$1048576&$B$2:$B$1048576,0),1)
It's not clear what you are trying to return, so this formula will return the corresponding value in column C. You can use this concept to return each value from the rest of the columns D:L, one by one, or concatenate them.

Resources