Excel create an array from non-stacked cells - excel

Sumproduct(array1,array2) is an excel formula that performs the dot product.
=Sumproduct({1,2,3},{7,0,5})
results in 1*7 + 0*2 + 5*3 = 22
I want to replace the first array by values stored in non-stacked cells ( for example: A1,A3,B7) I tried
=Sumproduct({A1,A3,B7},{7,0,5})
but it doesn't work. It seems I can't create an array from non-stacked cells.
Can you please help me create an array of non-stacked cells in Excel?

Try this as an array formula entered with ctrl+shift+enter.
=SUMPRODUCT(CHOOSE(ROW(1:3), A1, A3, B7), CHOOSE(ROW(1:3), 7, 0, 5))

Related

Excel vlookup get the highest value

Here is the excel function:
start date =IF(A6 = 1, C3, VLOOKUP(A6 -1, $A$6:$D$13, 4, FALSE))
end date =C6+B6
I intend to get the latest end date value if there is multiple rows on previous sequences, for example as below:
On the yellow cell, it should get the 23/2/2019 instead of 18/2/2019.
Use LOOKUP:
=IF(A12=1,C9,LOOKUP(A12-1,$A$6:$A$13,$D$6:$D$13))
Edit:
to get latest date you can use AGGREGATE function:
=IF(A6 = 1; C3; AGGREGATE(14;4;($A$6:$A$13=A6 -1)*$D$6:$D$13;1))
I think this will serve your purpose. This is formula for first start-date value and drag it downwards.
=IF(A6=1,$C$3,MAX(IF(A6-1=$A$6:$A$14,VLOOKUP(A6-1,$A$6:$D$14,3)+$B$6:$B$14)))
NOTE this is array formula so enter it with ctrl + shift + enter and check for curly braces around the formula. The screenshot to check for all conditions
Check for seq 6, I added two values sorted differently now

How to add values for alternative cells in Excel column?

In an Excel sheet, I want to add values A1, C1, E1 and so on.
I tried with
=IF(MOD(ROW(), 2) = 0, 1, 0)
I want to add values of H2,J2,L2,N2,P2 and all alternative cells.
Like that I2,k2,m2,o2 abd all alternative cells. Image attached.
Excel Image
One way of solving your issue is to use SUMPRODUCT.
=SUMPRODUCT((A1:L1)*(MOD(COLUMN(A1:L1),2)<>0))
Replace A1:L1 with the relevant range on your worksheet.
It will be better if you can provide some sample data and expected output next time :)
You need an array formula. (I'll use A1:E1 as the example range). First we need to assign either 1 or 0 to each cell.
Mod(Column(A1:E1),2)=0
Then we multiply each cell by that 1 or 0 to give either the cell value or zero as the result
a1:e1*mod(column(a1:e1),2)=0
Then we Sum them
=SUM(A1:E1*(MOD(COLUMN(A1:E1),2)=0))
and finally we enter this as an array formula by entering it using Control Shift Enter
Assuming that the range you want to add is A1:A10 try this FormulaArray
= SUM( $A$1:$A$10 * ISODD( ROW( $A$1:$A$10 ) ) )
or this if the range is A1:Z1
= SUM( $A$1:$Z$1 * ISODD( COLUMN( $A$1:$Z$1 ) ) )

How to give reference to a row number in excel formula?

I need this formula: C(n) = B(n)*A5. (n is the row number)
Literally, multiply the current selected row number in column B with A5
I tried =ROW function for creating a reference but failed.
I tried with this formula: C(2) =MULTIPLY(B=ROW(),A5) thinking it will be parsed to C(2) =MULTIPLY(B2,A5)
You have two options to accomplish this:
1. INDEX() formula:
=INDEX(B:B,ROW())*A5
2. INDIRECT() formula:
=INDIRECT("B"&ROW())*A5
Where ROW() is the number of cell you're entering this formula into.
Found it.
=MULTIPLY(INDIRECT("F" & ROW()),INDIRECT(("G" & 2)))
INDIRECT(("G" & 2)) even makes it better if you want to drag and copy the functionality to all the rows below.

Excel CountIf Formula With OR

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")

Find blank count in a row with most blanks within a 2D array of cells

I want a formula that will look in a 2D array of cells for the row that has the most blank cells in it. Then I want the number of that row's blank cells returned as shown in the picture. The "Title 2" row has the most blanks at 4 as displayed in B8. I would want the formula to take the whole table into considerations, so cells B2:G5
Or this array formula**:
=MAX(MMULT(0+(LEN(B2:G5)=0),TRANSPOSE(COLUMN(B2:G5)^0)))
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
Sometimes it's easier to break things up into two tasks:
A formula in Column H that counts blanks by row. Something like: =COUNTIF(B2:G2, "="&"") which you would drag down through row #5.
Then, just make Cell B8 the maximum of that new column: =MAX(H2:H5).
I'd be curious if there is some type of array formula trick to accomplish this is one formula. Nevertheless, personally, I find separating the logic into smaller, more manageable, formulas easier to maintain.
In H2 enter:
=COUNTBLANK(B2:G2)
and copy down. In B8 enter:
=MAX(H2:H5)
For example:
Several great answers already, but I'll throw this out there:
=MAX(COUNTBLANK(INDIRECT("B"&ROW(2:5)&":"&"G"&ROW(2:5))))
Enter as an array formula: Ctrl+Shift+Enter
This:
"B"&ROW(2:5)&":"&"G"&ROW(2:5)
… returns an array of strings {"B2:G2" , "B3:G3" , "B4:G4" , "B5:G5"}:
That array is fed to the INDIRECT function, which changes it into an array of ranges {B2:G2 , B3:G3 , B4:G4 , B5:G5}.
That new array is fed to the COUNTBLANK function, which (using your example) returns the array of numbers {2 , 4 , 1 , 3}.
That's fed to the MAX function, so the end result is the number 4.
It's a bit convoluted, so I'm wondering if my INDIRECT parameter can be simplified.

Resources