Using TRANSPOSE in an IF statement and Lookup Formula - excel

I am trying to use the result of a TRANSFORM inside an IF statement where if the value returned in transform is blank, the value_if_true should look up the value of the previous cell, add one to it and show that, otherwise just show the result of the transform.
My issue is that the formula inside value_if_true, returns #VALUE even though on evaluation it is calculating the right value to return but if I replace it with a static text it works fine.
Below is what I'm trying to do:
{=IF(TRANSPOSE(Master!A7:A110)="",INDIRECT("RC[-1]",0)+1,TRANSPOSE(Master!A7:A110))}
This is what works:
{=IF(TRANSPOSE(Master!A7:A110)="","blah",TRANSPOSE(Master!A7:A110))}
Thank You!

Are you sure the value in RC[-1] is a number? If it is text and can't be converted to a number, then it will return #Value
Also, are you entering this array formula into a single cell and then filling it, or are you array-entering it into an entire range at once? If you're array-entering it into the entire range at once, then also be aware that RC[-1] will always refer to the cell that is to the left of the top-left cell of the output-array range.

Sorry for responding so late, surprisingly using named ranges instead of explicitly calling them out has solved the problem. To explain:
This is my data in the 'Reference' sheet. It is merely week numbers expressed in descending YYYYWW format:
201701
201702
201703
201704
201705
201706
201707
201708
The size of this list changes as data for more weeks flows in, the maximum items it can have is 104 weeks (two years rolling data). I've selected the entire 104 row range say $A$1:$A$104 that this list can expand to occupy and named it ListOfWeeks
On my display sheet I have selected the full 104 column range that these dates will be transposed into say $I$6:$DH$6 then entered the following formula into the formula bar:
=IF(TRANSPOSE(ListOfWeeks)=0,"",TRANSPOSE(ListOfWeeks))
followed by a Ctrl+Shift+Enter and it is working just fine.

Related

excel SUMIF not giving right answer

I have a table with data and I am trying to do the following on another sheet. I am trying to sum the price of items in a column if the date is a particular date. I filtered all the dates using UNIQUE on the second sheet and doing a SUMIF based on those values. The problem is, the results are all slightly less than the actual value obtained by manual summation/ highlighting the relevant cells and seeing the sum on the bottom. Why is this happening? The discrepancy cannot be attributed to any single cell it is supposed to sum.
btw anyone knows why the similar questions box seems to be bugging out? The original text stays in place as I scroll, like some kind of ghost effect.
edit: here is a picture of the problem
Here is what I think is the explanation.
From the documentation: The sum_range argument does not have to be the same size and shape as the range argument. The actual cells that are added are determined by using the upper leftmost cell in the sum_range argument as the beginning cell, and then including cells that correspond in size and shape to the range argument
Your formula: =SUMIF(F2:F31,"="&H2,G:G)
thus evaluates to =SUMIF(F2:F31,"="&H2,G1:G30)
Because of the offset in the ranges, the last instance of range = H2 gets dropped. And 34.86-33.67 = 1.19 which is the last cell that should be added.
In other words, g1 is evaluated against f2, and g13 is evaluated against f14. Since f14 does not contain 3/2/2020, the 1.19 does not get added by SUMIF
Sometimes this is useful. But here, as you note, it has an unwanted result.
It works in your first case because both range and sum_range start in the same row.
All you need to do to get it working in your second case is to ensure both ranges start at the same row.
eg: =SUMIF(F2:F31,"="&H2,G2) would work

Index Match Formula Keeps Continuing

I'm trying to create a dashboard, where upon selecting a company from a dropdown list, it will list all of the company's bankers where the data is on another worksheet tab.
So far, the Index Match formula seems to be running fine, however, it keeps on running and lists the bankers from other companies. How can I fix this?
File can be downloaded here: https://drive.google.com/file/d/1fw7yh4AEF1vx3cuG6E_1RBTrTD_k74KD/view?usp=sharing
You can try below approach by pasting below formula in cell E5:
=IFERROR(INDEX(RAW!$D$2:$D$279,SMALL(IF(RAW!$B$2:$B$279=$C$5,ROW(RAW!$D$2:$D$279)-1,10^10),ROWS($A$1:A1))),"")
This is array formula so it needs to be committed by CTRL+SHIFT+ENTER and then copy it down as much needed.
Explanation:
INDEX is retrieves the range reference from the defined GRID based on the row and column reference.
In this particular case, we intend to extract the references sequentially. This is performed by SMALL(IF(RAW!$B$2:$B$279=$C$5,ROW(RAW!$D$2:$D$279)-1,10^10),ROWS($A$1:A1))
Within this formula, first portion is the ARRAY building IF formula as below
IF(RAW!$B$2:$B$279=$C$5,ROW(RAW!$D$2:$D$279)-1,10^10) which tests cells in column B if they match criterion value. If the value matches then ROW reference is returned and if it doesn't then it returns a very large value i.e. 10^10. We subtract 1 from row reference as the data starts from row 2 so it should be (n-1) in principle. This arrangement produces an ARRAY like {1;2;3;4;5;6;7;10000000000....} for value "Acorda".
But we need to pass one element at a time to INDEX formula so this is done by SMALL(IfBasedArray,k) where k part is serially generated by ROWS($A$1:A1) which starts with 1 and increments downwards as the formula gets copied which thus enables INDEX to return desired results.
Finally, when the matches are finished then big number i.e. 10000000000 gets fed and generates an error which then is covered by IFERROR formula to return blank!
Please apply this formula to your sheet's E5 and copy down. Note that I created the named range Coms which refers to RAW!B2:B279.
=IFERROR(IF(INDEX(Coms,MATCH($C$5,Coms,0)+ROW()-ROW(E$5))=$C$5,INDEX(Coms,MATCH($C$5,Coms,0)+ROW()-ROW(E$5)),""),"")
If you prefer, the name in the formula can be replaced with the address, as you had it originally, or you define the named range to expand dynamically.
A simpler option than the 2 previous answers (doesn't require an CSE array entered formula or multiple nested INDEX/MATCHES) would be to have a couple of 'helper' cells in say G5/G6
Start Row would be =MATCH(C5,RAW!B:B,0) This finds the first row on your RAW sheet where the selected company appears
Advisor Count would be =COUNTIFS(RAW!B:B,C5) counts how many rows there are for this particular company
Then your formula in cell E5 becomes =IF(D5<=$G$6,INDEX(RAW!$D:$D,$G$5+D5-1),"") which you can drag down.
screenshot showing formulas/result

How to define a range, using an Excel formula

In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.

Excel formula to create a unique list produces a 0 at the bottom that I cannot remove

Here's my situation
Goal: create a unique list in sheet2 based on a list with duplicates in sheet1.
What I've tried: ={IFERROR(INDEX(Sheet1!$B$2:$B$100,MATCH(0,COUNTIF($B$2:B2,Sheet1!$B$2:$B$100),0)),"")}
The issue: the formula produces the list I'm looking for, however it produces a 0 at the end of the list (e.g. B3 through B25 is correct but cell B26 has a 0). The problem is I can't figure out how to delete it. I've tried an if(0,"") statement and that doesn't work. Note, my list in Sheet1 only has about 25 total entries, however I want the formula to read to B100 to account for additional material. I did however try the formula ending exactly where my list ends and that does not produce a zero.
If anyone has any ideas, please let me know.
Thanks
That is because the blank cell at row 26 will satisfy the equation as unique:
You can add a another criterion:
IFERROR(INDEX(Sheet1!$B$2:$B$100,MATCH(1,(COUNTIF($B$2:B2,Sheet1!$B$2:$B$100)=0)*(Sheet1!$B$2:$B$100<>""),0)),"")
This is an array formula and needs to be confirmed with Ctrl-Shift-Enter.
Another method would be to make the reference data set dynamic:
=IFERROR(INDEX(Sheet1!$B$2:INDEX(Sheet1!$B:$B,MATCH("ZZZ",Sheet1!$B:$B)),MATCH(0,COUNTIF($B$2:B2,Sheet1!$B$2:INDEX(Sheet1!$B:$B,MATCH("ZZZ",Sheet1!$B:$B))),0)),"")
This will set the referenced data to the extents, and as new data is added it will automatically grow or shrink and thus never refer to a blank cell.
Use the above if the data on sheet 1 is Text if it is numbers replace both "ZZZ" with 1E+99

How do I use an array formula over a whole column or varying range?

I have a spreadsheet that I'm importing data into. I need to find the value within a column that is closest to zero. The column contains both positive and negative values, and the value closest to zero will be used in another formula. I've found an answer using an array formula, but it will only work for a fixed range (e.g. K2:K10), and the number of records imported into my sheet will vary each time I use it.
Here's what I have so far:
=INDEX(K:K,MATCH(MIN(ABS(K:K)),ABS(K:K),0))
Is there a way to apply an array formula over an entire column and just include non-zero cells other than the column title? Or possibly just cells with numerical values? Or is it possible to control the range that it applies to?
We can dynamically find the last cell in the range by using another INDEX/MATCH formula that is not an array:
=INDEX(K:K,MATCH(1E+99,K:K))
This will find the last cell that has a number in column K.
So we now use this as the last cell in the range:
=INDEX($K$2:INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K)))),ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K))),0))
And now the formula is dynamic.
This formula is still an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. If done correctly then Excel will put{} around the formula.
If as you pointed out there is a chance of deleting row 2 then all the K2 references will also be deleted.
In place of K2 we can use INDEX(K:K,2) It will now always look at the second row and will not error when row 2 is erased. So use this instead:
=INDEX(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(INDEX(K:K,2):INDE‌​X(K:K,MATCH(1E+99,K:K)))),ABS(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K))),0))
There is nothing wrong with the Offset() function in small amounts, but it is a volatile function. Which means that it will calculate EVERY TIME excel calculate whether the data to which it is dependent has changed or not.
For the benefit of anyone reading this post, I ran into another issue and found a way around it. Scott Craner's answer above worked well until I ran a macro that I had for that sheet, which would delete certain rows. If row 2 got deleted, the formula would give a #REF error, because it was trying to call $K$2.
My solution was to replace $K$2 with
OFFSET(K1,1,0)
Therefore, the complete formula would be:
=INDEX(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)))),ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K))),0))
And as Scott mentioned, remember to hit Ctrl-Shift-Enter to execute the array formula.

Resources