I want to get the sum of the text inside (<number>) like the table below
tried this formula but this does not work or throws an error
{=SUMIF($D1:$D7, $F1&"(*", -RIGHT($D1:$D7, 3))}
RIGHT works okay with SUM like this formula
{=SUM(-RIGHT(D1:D7,3))}
The SUMIF function takes the following parameters:
the range of cells to inspect
the criteria
the range of cells to sum
So the third parameter MUST be a range of cells.
But -RIGHT($D1:$D7, 3) doesn't return a range of cells - it returns an array of values.
That means SUMIF isn't the right tool. Instead, make your {=SUM(-RIGHT(D1:D7,3))} array formula conditional by multiplying each value by one or zero based on the values in F:
{=SUM( (LEFT(D$1:D$7,2)=F1) * (-RIGHT(D$1:D$7,3)) )}
This is an array formula so must be entered by using Control-Shift-Enter instead of just Enter alone. Put it in G1 and then copy it down to the other cells.
Related
If you have a CSE array constant as follows in cell A1:
{={2,4,6,8}}
How can you get a specific element from the array constant? I tried the following formulas but they all return the first value of the array constant (2).
=INDEX(A1, 0)
=INDEX(A1, 1)
However, it does work if the array is not a reference. The following formula returns the 3rd element (6).
=INDEX({2,4,6,8},3)
Thank you
You could put the array constant in a Name instead of a cell.
Then INDEX will work with it properly with no implicit intersection.
Or you could parse the formula using the FORMULATEXT function, but that sounds tedious.
Try =INDEX(A1#,1). The # tells excel that A1 is a spill formula (more than 1 cell long). The array index starts at 1, not 0 in this case.
As a side note, Index knows you are referring to an index, not a row, when you give it a 1D array. In your example =INDEX(A1#,4) and =INDEX(A1#,1,4) return the Fourth item in your array (8 in this case), but =INDEX(A1#,4,1) will give you the error #REF!. If you define your array vertically {={2;4;6;8}}, =INDEX(A1#,4) and =INDEX(A1#,4,1) both work.
Edit: It looks like this does not always work in Excel 365 when a an array formula is created using Ctrl+Shift+Enter. I think this is due to the changes in 365. Array formulas have pretty much been replaced with spill formulas. Entering ={2,4,6,8} is mostly equivalent to a pre-365 array formula, but creating an array formula with Ctrl+Shift+Enter confines the output to as many cells as selected. In Dan's case, he selected only one cell and the formula doesn't automatically spill, so the formula is confined only to that cell. Excel seems to treat that cell as if it only contains that array element. If you select 2 cells and enter an array formula then =INDEX(A1#,2) will work but =INDEX(A1#,3) returns #REF!.
Edit2: It is possible with the FORMULATEXT Function as #DickKusleika suggested. Here is a function adapted from ExcelJet that does the job.
=LET(
DesiredIndex, 1,
ArrayFormulaRef, A1,
Formula, FORMULATEXT(ArrayFormulaRef),
FormulaLen, LEN(Formula),
CSVStart, FIND("{",Formula,2),
CSV, MID(LEFT(Formula,FormulaLen-1),CSVStart+1,FormulaLen),
TRIM(MID(SUBSTITUTE(CSV,",",REPT(" ",LEN(CSV))),(DesiredIndex-1)*LEN(CSV)+1,LEN(CSV)))
)
I want to get the count of cells used in an excel function.
For example say I have a sum function ='CV'!D11+Farmer!D11+'County'!D11+Rt!D11+WT!D11+'Country'!D11
I need a function that will tell me how many cells were used to get the total sum. In this case it is 6. The tricky part is if one of the cells used is blank I do not want it counted. For instance say cell D11 on the Farmer sheet is blank I do not want it counted in the total. So the total should be 5.
Use COUNT:
=COUNT('CV'!D11,Farmer!D11,'County'!D11,Rt!D11,WT!D11,'Country'!D11)
It will only count the cell if it has a number
You should really try to collate all your data in to a single sheet before running calculations. For the sake of example, I'll assume you have it in the range A1:A5, then you can add handling of the various cases using array formulas:
Get the count of non-empty cells (the ISBLANK function is untrustworthy in my experience): {SUM(IF(LEN(A1:A5)>0,1,0))}
Get the sum of those cells: SUM(A1:A5)
(must use Ctrl+Shift+Enter to enter the formula as an array formula, you will know it worked if the formula shows like {IF(...)} with the curly brackets)
Because blank/missing values are treated implicitly as 0 in the SUM function, this case is simple. If you have other validations then you'd have to write an array formula for the summation as well. For example, only including numbers between a min and max threshold (e.g. if you want to exclude outliers):
{SUM(IF(AND(A1:A5 >= yourMinValue, A1:A5 < yourMaxValue), A1:A5, 0)}.
If I understand your question correctly, you want to literately count the number of cells used in a formula which in your example is summing 6 values from 6 different locations.
I used the following example to demonstrate my solution:
The sum of =A1+B1+C1+D1+E1+F1 is 10 where cell C1 has a 0 value in it but cell E1 is blank.
Using the following array formula I was able to count the number of cells that have a value other than 0:
=SUMPRODUCT(IFERROR(ABS(N(INDIRECT(TRIM(MID(SUBSTITUTE(RIGHT(FORMULATEXT(A3),LEN(FORMULATEXT(A3))-1),"+",REPT(" ",100)),100*ROW(INDIRECT("1:"&LEN(FORMULATEXT(A3))))-99,100)))))>0,0)*1)
Please note you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to use a combination of TRIM+MID+SUBSTITUTE+RIGHT+FORMULATEXT+REPT+ROW+INDIRECT to extract the cell addresses from the original formula, then use INDIRECT to convert the cell address into the values stored in those cells, then use a combination of IFERROR+ABS+N to find out if any of these values are not 0, and lastly use SUMPRODUCT to add up all the TRUE results.
It is obvious that there are a couple limitations of my solution:
If your actual formula is not strictly in the form of A+B+C+D+E+F, then my SUBSTITUTE part of formula will need further modification;
The formula will treat cells containing 0 as blank and does not include them in the count.
Let me know if you have any questions. Cheers :)
I have the below formula that Lookup the A1:A10 appropriated Score Number.
{=INDEX(Table1[ScoreNum],MATCH(A1:A10,Table1[ScoreWord],0))}
I need calculate the AVERAGE result of this entire array.
But when using this:
{=AVERAGE(INDEX(Table1[ScoreNum],MATCH(A1:A10,Table1[ScoreWord],0)))}
Returns the first looked up result with Index/Match, against returns the average of all returnable values whit this array formula.
How can do that?
The sample Workbook file
Sheet1
Sheet2: Table1
Note: The formula in B11 is: =AVERAGE(B1:B10) and returns the true value. I need return this without using the B helper column, directly in a single cell (A11) with the true form of formula shows in the picture.
Very truly yours.
Another method:
=AVERAGE(INDEX(Table1[Column2],N(IF({1},MATCH(A1:A10,Table1[Column1],0)))))
also entered as an array formula.
I would use, instead, this array-formula:
=AVERAGE(AVERAGEIF(Table1[Column1],A1:A10,Table1[Column2]))
To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.
The AVERAGEIF function returns the array {1;0.8;1;0.2;0.6;0.8;1;1;0.6;0.2} which is what you are showing in your column B in your screenshot.
We then AVERAGE that array by nesting the AVERAGEIF(.. within the AVERAGE function.
I am having trouble with an Excel-function.
On sheet A I want to get the value of a cell that is located x-columns to the right of cell F2.
X is a variable number and is determined by the value of cell A1. Currently, the value is 5.
=(OFFSET(sheetA!F2,0,sheetA!A1))
This formula works. However, I want to include this function into a MATCH and INDEX function that is located on another sheet (B).
I know that I can use the following formula to get value of $F$2
INDEX(sheetA!F:F,MATCH(sheetB!C4,sheetA!A:A,0))
Combining them, results in the following formula:
=INDEX((OFFSET(sheetA!F2,0,sheetA!A1)),MATCH(sheetB!C4,sheetA!A:A,0))
This formula generates a #REF!-value.
If I evaluate the formula, I see the following steps:
=INDEX((OFFSET(sheetA!$F$2,0,5)),MATCH(sheetB!C4,sheetA!A:A,0))
=INDEX((sheetA!$K$2),MATCH(sheetB!C4,sheetA!A:A,0))
=INDEX((sheetA!$K$2),MATCH("BTC",sheetA!A:A,0))
=#REF!
Why do I want to use MATCH and INDEX?
Because while the values on sheet A are "fixed", the values of sheetB!C4 are floating/variable. Therefore, I need to locate the correct row first. The correct column can be done with the offset-part.
Thank you for your help.
Try this
=INDEX((OFFSET(SheetA!F:F,0,SheetA!A1)),MATCH(SheetB!C4,SheetA!A:A,0))
Syntax of INDEX is
INDEX(array, row_num, [column_num])
where, array is range of cells. When you use =INDEX((OFFSET(sheetA!F2,0,sheetA!A1)),MATCH(sheetB!C4,sheetA!A:A,0)), (OFFSET(sheetA!F2,0,sheetA!A1)) returns sheetA!$K$2 which is a cell not a range.
I'm trying to set up a formula to automatically calculate the % change between the most recently added cell in a range (which includes #N/A values at the bottom of the range) and the cell immediately above it. I've been using this formula to obtain the value of the bottom not #N/A cell:
LOOKUP(2, 1/NOT(ISNA(G8:G19)), G8:G19)
Which is working fine. My first thought on how to reach the cell above it was to use OFFSET, like so:
OFFSET(LOOKUP(2, 1/NOT(ISNA(G8:G19)), G8:G19), -1, 0)
but this gives me an error, I think because the lookup function is returning the value in the cell rather than the cell reference. How should I format a function to return the value of the cell above the last non-N/A cell in a range?
Try this alternative for seeking the last non-error, numerical value in column G.
=index(G:G, match(1e99, G:G))/index(G:G, match(1e99, G:G)-1)
Using MATCH to find the last number in a column returns the row number to INDEX. It is a simple matter to subtract 1 from a row number.
One method is to use this array formula:
=INDEX($G$8:$G$19,MATCH(2,IF(NOT(ISNA($G$8:$G$19)),1))-1)
Being an array formula it must be confirmed with Ctrl-Shift-Enter on exiting edit mode instead of enter. If done properly then Excel will put {} around the formula.