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)))
)
Related
E.g. I want to check if array (B1:B10) concatenated with (C1:C10) contains the text in cell A1, and if it does, return "Detected".
Some background info:
1) When those 2 arrays are concatenated together, they should have same length as A1.
2) Arrays concatenated with equivalent range value e.g. B1 with C1, B2 with C2.
EDIT
Using BigBen's template below, I tried =IF((MATCH(LEFT(A1,3),B1:B10,0)=MATCH(RIGHT(A1,3),C1:C10,0)),"detected","")
and managed to get the desired result; however, it does not account for duplicates 'bar' within column C.
enter image description here
enter image description here
IIUC, you can use MATCH for this:
=IF(ISNUMBER(MATCH(A1,B1:B10&C1:C10,0)),"Detected","")
IMPORTANT: Note that depending on your version of Excel, you may need to enter the formula with Ctrl+Shift+Enter.
This is probably very brittle, but given the data outline in BigBen's answer, this array formula (needs to be confirmed with Ctrl+Shift+Enter) returns the expected result:
=IF(ISNUMBER(SEARCH(A1,TEXTJOIN("|",FALSE,B1:B10&C1:C10),1)),"Detected","")
It basically joins each value in column B with the corresponding value in column C, then checks to see if the key word is detected in the resulting string. It is also dependant on you having a version of Excel that has the TEXTJOIN function.
Here is a view of the formula evaluation:
*note, I trimmed the data down to only 5 records, but you get it...
I'm trying to calculate with an Array Formula (in Cell D2) what i'm calculating long-way in cell D11. The issue i'm having is that it appears my Array Formula is not evaluating the inputted array one-by-one. As an example, I want the second comparison that the formula does to be the following:
Check if ([B7>0] AND [C7=0]) and, if so, return D7.
But I think it's only checking to see if every value in the column B array is >0 and if every value in the column C array is =0.
The screenshot below details my problem. Thanks!
https://i.imgur.com/8eVp7X7.png
You don't need an array formula, you can use
=SUMIFS(B6:B10,B6:B10,">0",C6:C10,0)
Array formulas don't like AND. See here. This array formula would work
=SUM(IF(B6:B10>0,IF(C6:C10=0,B6:B10)))
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 have a database with the relevant data in the same rows across several sheets, with data in every other column. I have been trying to use 3D ranges with AVERAGE/SUM and OFFSET but I can't seem to figure it out. I am getting a #VALUE error during the OFFSET part. Here is the setup I have been using.
=AVERAGE(OFFSET('Sheet 1:Sheet 4'!A1,0,COLUMN(A1)*2-1))
The sheet names do have spaces in them so the space in my above formula between the word Sheet and the number is intentional. I have tried the 3D range with just the average/sum functions and it works fine. Are the 3D ranges not compatible with the OFFSET function?
Try...
=AVERAGE(N(OFFSET(INDIRECT("'"&{"Sheet1","Sheet2"}&"'!A1"),0,COLUMN(A1)*2-1)))
or
=AVERAGE(N(OFFSET(INDIRECT("'"&$G$2:$G$3&"'!A1"),0,COLUMN(A1)*2-1)))
...where G2:G3 contains the sheet names. Note that the second formula needs to be confirmed with CONTROL+SHIFT+ENTER, not just ENTER.
Hope this helps!
FIRST EDIT
While an array formula is still required, you can avoid having to confirm the formula with CONTROL+SHIFT+ENTER, and you can avoid having to list your sheet names in a range of cells.
1) First define the name SheetNames as follows...
Refers to: ={"Instrument Partners","Supply Partners","Repair Partners","Wholesale Partners"}
2) Then try...
=AVERAGE(INDEX(N(OFFSET(INDIRECT("'"&SheetNames&"'!A1"),0,COLUMN(A1)*2-2)),0))
...which only needs to be confirmed with ENTER.
SECOND EDIT
"'"&SheetNames&"'!A1" returns the following array of text values...
"'Instrument Partners'!A1"
"'Supply Partners'!A1"
etc...
This array of text values is passed to INDIRECT, which returns the following array of references...
'Instrument Partners'!A1
'Supply Partners'!A1
etc...
In turn, this array of references is passed to OFFSET, which also returns an array of references based on the row and column offsets...
OFFSET('Instrument Partners'!A1,0,COLUMN(A1)*2-2) --> 'Instrument Partners'!A1
OFFSET('Supply Partners'!A1,0,COLUMN(A1)*2-2) --> 'Supply Partners'!A1
etc...
Then we retrieve the values by passing this array of references to the N() function...
N('Instrument Partners'!A1) --> returns actual value from the cell reference
N('Supply Partners'!A1) --> returns actual value from the cell reference
etc...
Then we pass this array of values to the INDEX function, which returns an array of values and allows the formula to be confirmed with just ENTER, instead of CONTROL+SHIFT+ENTER.
Lastly, the array of values is passed to the AVERAGE function, which returns the actual average.
I was looking for a excel formula to do a task. Tried using Countif,Countifs. But with no luck. Any help is appreciated.
Task as below.
Type--------------Primary Color--------------Secondary Color
Car----------------Blue--------------------------Red
Bike--------------Black-------------------------White
Car---------------Blue--------------------------Blue
I need a formula which gives me a count of Cars having blue as their colour(Either Primary Or Secondary)
You can use following array formula (confirmed with Ctrl+Shift+Enter to calculate count of blue cars:
=SUM(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
or non array version:
=SUMPRODUCT(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))
This part:
(B2:B4="Blue")+(C2:C4="Blue")>0
is an alternative way of expressing OR (not suitable for array formulas as it always returns a single value). N function converts boolean values to 0 and 1.
Edit: updated the formulas to include condition for A column.
What about adding a column with the following
=IF(OR(B1="Blue", C1="Blue"), 1, 0)
and copy that down.
On another sheet you can sum that new entire column with
=SUM(D:D)
Of course you will have a worksheet reference to the other sheet attached to the SUM formula.
If you don't want to do an array formula you can just do 2 countifs formulas (which are easier for people to read than array formulas)
=COUNTIFS(b8:b12,"Blue")+COUNTIFS(c8:c12,"Blue")