Using COUNTIF, OFFSET, MATCH in Excel - excel

I keep getting an error around this certain part of my COUNTIF function and cannot find out why. I believe it's cause the Offset function won't output a range. It seems to work fine if I manually put a range, but that isn't an option.
How do I get a range as an output using Match?
=COUNTIFS(OFFSET(Sheet2!$A$1,0,MATCH(I$1,Sheet2!1:1,0)),"*Accountable*")

I think you want to count "Accountable" from $A$1 until the found match, so you are trying to "expand" the cell A1 by as many cells. The parameter to enlarge the number of columns in the OFFSET function is parameter 5. Try this:
=COUNTIFS(OFFSET(Sheet2!$A$1,0,0,1,MATCH(I$1,Sheet2!1:1,0)),"Accountable")
' ^^^
You could use INDEX to achieve the same. (sometimes preferred for its non-volatility):
=COUNTIFS(Sheet2!$A$1:INDEX(Sheet2!1:1,MATCH(I$1,Sheet2!1:1,0)),"Accountable")

Solved:
A.S.H's tip on keeping the ranges the same solved most of it.
The second bit I was running into was just a miscalculation of columns.
It needed to be the match function and then minus 1 column.

Related

Workaround for named range Search function issue in Excel

I have a bank export of Credit card vendors. As these vary, I use unique strings contained in each to identify them. For example here is a lookup table excerpt.
First Lookup
I then apply a formula =INDEX(First_level,MATCH(TRUE,ISNUMBER(SEARCH(Keywords,C3374)),0)) to produce this:
First calc
I found this formula here https://exceljet.net/formula/get-first-match-cell-contains
Then I reapply the formula to the result ie the First_Level using this formula =INDEX(Second_Level,MATCH(TRUE,ISNUMBER(SEARCH(Frst_Lev_Check,H44)),0)) with this Lookup.
Second Lookup
Most of the time it works, but for this I get the following
Second calc, where the first level classification is correct, but the second level one is completely wrong.
When I've gone into the depths of the formula, the issue is that the Search function is returning the wrong value.
This appears to be a known issue: https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-use-named-range-in-search-function/14c8c989-bed0-48f9-bce0-c0894571b557
Ideas welcome on workarounds/how to solve the problem.
Cheers Jon
Would you consider:
=MATCH("Apple",List)
and
=MATCH("Pear",List)
to return 1 and 2 respectively.
A couple of things in regards to your question:
The correct syntax for search is =SEARCH(find_text,within_text), so the correct formula would be =SEARCH("Pear",List).
The reason why you are getting the #Value is, because you are applying search to a range, but the function is only intended for cells.
The best ways to see if a value exists in a range are the countif and match function:
The countif function shows you how many times the a value is in a range:
The match function shows you in which row the the first value is:

Index Match Works on some cells, not others

I was using this Index Match formula with no issues:
=INDEX('Rain Data For 9 Stations'!A:S,MATCH(RainWICSProximity!J100,'Rain Data For 9 Stations'!A:A,0),INDEX($N$4:$N$12,MATCH(H100,$M$4:$M$12,0)))
I added more data, and it now only returns some values, while returning #N/A for others, even though there is a value to return.
Index returns the value in a range.
What you are doing is =INDEX(MATCH(),INDEX(MATCH())). It works due to some luck, because sometimes the second Index() returns cell with value as well. However, if the second index returns cell with an empty value, then the first index has to return something like =Index(4,0), which is #N/A.
In general, try =Index(Match(),Match()).
To see where exactly the error is, select the cell with the formula, go to the Excel ribbon >Formulas>Evaluate Formula.
Then press a few times Evaluate Formula and see what happens:
See this answer for step-by-step formula evaluation.
#Vityata was correct, Index, Match, Match works wonderfully, also, my original formula does work.
The issue was, I had calculate set to Manual, not auto, in excel settings.
I believe you need to expand your range. I am not real familiar with Index Match but trying to learn to use it more, but I believe it is kind of like VLOOKUP. Your ranges $N$4:$N$12 and $M$4:$M$12 is where it is looking right? If so, those ranges are not expanding even though you added more data. So you need to expand it to like $M$4:$M$100 or whatever. Or expand it to find the last row which is what I usually do. like mine would be "$M$4:$M" & LastRow & "" or something like that.

Excel, extra brackets change value of formula?

I am adding the values of several cells from two sheets in excel.
I am using the formulas below to calculate this.
My question is why to two formulas aren't giving the same result? As far as I can tell, the only difference is that the 2nd formula has an extra bracket, which shouldn't change anything?
=SUM(SUMIFS('Ark1'!F15:F75;'Ark1'!E15:E75;{"adgangsareal bolig";"fællesrum bolig"}))+SUM(SUMIFS('Ark2'!F11:F126;'Ark2'!E11:E126;"bolig"))
=SUM((SUMIFS('Ark1'!F15:F75;'Ark1'!E15:E75;{"adgangsareal bolig";"fællesrum bolig"}))+SUM(SUMIFS('Ark2'!F11:F126;'Ark2'!E11:E126;"bolig")))
The latter formula has been working perfectly until now through my Work, but for this specific value i needed to remove the extra bracket.
Jacob is right that its the array bit that is causing the problem, but really the problem is caused by the + sign in an expression containing an array which causes the expression to be evaluated as an array formula. You can fix this by changing the + to ; (or whatever the argument separator character is in your locale).
A simpler example (my locale uses , rather than ;):
=SUM({5,10}+20)
results in 55 (the expression evaluater creates (5+20)+(10+20) using the array expansion rules and then passes {25,30} to SUM) but
=SUM({5,10},20)
results in 35
In your first SUMIFS() you have the criteria listed as an array. When using SUM() around the first SUMIFS() alone, it is returning the sum of the range that meets the first criteria being true in the range, then repeats for the second critera, and then it adds the second SUMIF().
When you add the parentheses, you SUM() the first SUMIF() total for the first array value AND the second SUMIF(), and then you are repeating for the second array. So you are getting that second SUMIF() total added twice essentially.
I believe you want something like this:
=SUM(SUMIF('Ark1'!E15:E75;"adgangsareal bolig";'Ark1'!F15:F75);SUMIF('Ark1'!E15:E75;'Ark1'!F15:F75;"fællesrum bolig");SUMIF('Ark2'!E11:E126;"bolig";'Ark2'!F11:F126))
Try this:
=(87,35+464,71-87,35-464,71)
=87,35+464,71-87,35-464,71
2nd formula results correctly in ZERO, while
1st one results in very small number(-0,0000000000000568434)
Add more decimal places to see it.
I think it is a BUG and has something to do with different type of numbers (decimal, floating,...).

Using a formula with a range having a variable

I have columns with a number of rows. I also have a module that counts certain cells when conditional formatting evaluates to true within the columns.
I can use a formula such as
=CountCFCells(A2:A201,README!$A$2)
and I get the correct result. However, I only want to examine the first X amount of rows (not all 201) I need to have a variable for the end row. I've defined NoR = 30 using the name manager and changed my formula to
=CountCFCells("A2:A" & NoR,README!$A$2)
however, this returns an error. It appears that the variable is substituted into the formula, but the range is in double quotes like
=CountCFCells("A2:A30",README!$A$2)
I believe the double quotes around my range is causing the error. Does any one know a solution to this problem? Thank you
Personally I avoid INDIRECT whenever possible as it's volatile - and I suspect your function takes a bit of calculating. I'd suggest INDEX instead:
=CountCFCells(A2:INDEX(A:A,NoR),README!$A$2)
This construction is still semi-volatile (it will recalculate when you first open the workbook) but better than fully volatile.
Is the function CountCFCells is expecting a range as an input, rather than a string? If so, try INDIRECT, like so:
=CountCFCells(INDIRECT("A2:A" & NoR),README!$A$2)

Use of ROW() or COLUMN() in OFFSET(...) generating #N/A! error

I want to have a cell at the top of a column of data which uses a worksheet function to record the total number of cells below it which contain data. There are no gaps in the column, so I figure I don’t need to use COUNTA, it would be more efficient to find the first blank cell. To this end I have the following function in cell R12:
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,1000,1)),0),0)-1
This worked fine until I tried to use a named reference cell to define the resized range a bit more flexibly… replacing the above with
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,ROW(last_cell)-ROW(),1)),0),0)-1
gives #N/A! in the cell. As a formula =ROW(last_cell)-ROW() works fine on its own so it’s a puzzle to me why it doesn’t work in the compound formula… even replacing a 1 in the OFFSET parameters with ROW(A1) throws an error.
I can work round it, but this behaviour is really annoying! Can anyone shed any light on this?
The problem you are having is that the OFFSET function is expecting a long integer as its [height] parameter and you are shoving an array of integers at it. Yes, there is only one integer in the array but it is still an array and OFFSET is jumping ship at the first sign of potential trouble. If you evaluate the formula as suggested by Grade 'Eh' Bacon above, you will see that the result of that simple math subtraction is wrapped in braces (e.g. { and } ). You need to remove any indication that the [height] parameter is being fed an array or OFFSET will keep choking.
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12, 1, 0, MIN(ROW(last_cell)-ROW()), 1)),0),0)-1
There are any number of basic Excel worksheet functions that can take an array of 1 and turn it into an integer. I've used the MIN function. MAX, SUM, AVERAGE, etc. would all work. They take an array of numbers and return a single integer, even if that array of numbers has only one number.
On a related topic, I find it admirable that you are trying to reduce the calculation cycles in your workbook but you are missing one important consideration. The first thing you should do is throw out the OFFSET function altogether.
=MATCH(TRUE,INDEX(ISBLANK($R$12:INDEX($R:$R, ROW(last_cell)+1)), , ), 0)-1
OFFSET is a volatile formula that recalculates whenever anything in the workbook changes. Opting for the INDEX function equivalent takes the formula out of volatile mode and it will only recalculate when something that affects its outcome changes.
You may be interested in the way OFFSET erroneously treats floating point errors. See OFFSET_Floating_Point_Error for more on that.
Having had a chance to play around a bit, I'm still confused!
OFFSET itself doesn't seem to have a problem accepting the return values of ROW and COLUMN as parameters. To use a trivial example, this formula works:
=COUNTBLANK(OFFSET($R$12,ROW(1)+1,0,ROW(R20)-COLUMN(),1))
Trying different ways of eliminating OFFSET from the expression, I came up with:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(13,18)&":"&ADDRESS(1012,18))),0),0)-1
Which works, at the cost of swapping OFFSET for INDIRECT (which I'm hoping is the lesser of 2 evils!) However I would prefer to use:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROW(last_cell),COLUMN()))),0),0)-1
Which doesn't work, giving #N/A! again, as does changing any of the explicit integers to ROW or COLUMN expressions.
Individually, I've tried OFFSET, INDEX, ISBLANK and MATCH with ROW and COLUMN expressions and they all seem to work, so it seems to be something about using them in compound formulae which is throwing the error.

Resources