I'm trying to find a formula that results in the following:
sum(max(a,b),max(c,d),....)
I tried using =SUM(MAX(0,($D$1:$P$1)-$P$3) as an array formula, but this results in excel taking the maximum of all the entries, instead I want the sum of all maximums.
You want to sum a range, say A1:H1 if it's greater than a cell, say H3. But you don't want to sum the total, you want to sum the differences between the cells in the range that meet the criteria and the cell they are being compared to, right?
=SUMIF(A1:H1,">"&H3)-(COUNTIF(A1:H1,">"&H3)*H3)
It doesn't need to be entered with ctrl shft entr as sumif is already an array formula. Adapt to your conditions as needed.
=SUMPRODUCT((D1:P1-P3>0)*(D1:P1-P3))
The first set of parens returns a bunch of Trues and Falses. When multiplied, Trues are like 1's and Falses are like 0's. So when something is below zero, it gets multiplied by zero and becomes zero.
Related
I need a count if function that counts me the cells that meet a certain criteria. This should be done with countifs. The formula is the following:
=COUNTIFS(Orders!D:D;"*Ecolab*";Orders!B:B;">=01/01/2019";Orders!U:U;">=36";Orders!K:Q;">=1")This formula returns me an value type error.
This formula works well until I introduce the last condition orders!K:Q;">=1"
I would like a formula that counts if the word Ecolab is present in the cell; if the date is after or equal 01/01/2019; if the column U has more or equal than the number 36 and if there is at least a "1" in the cells in the row from column K to column Q. I could do this by easily replicating the countifs several times, (i.e =COUNTIFS(Orders!D:D;"*Ecolab*";Orders!B:B;">=01/01/2019";Orders!U:U;">=36";Orders!K:K;">=1")+COUNTIFS(Orders!D:D;"*Ecolab*";Orders!B:B;">=01/01/2019";Orders!U:U;">=36";Orders!L:L;">=1")+...........+COUNTIFS(Orders!D:D;"*Ecolab*";Orders!B:B;">=01/01/2019";Orders!U:U;">=36";Orders!Q:Q;">=1")
But I would rather not include such a long formula as it would create confusion for the ultimate user of the excel sheet
Per my comment above, you could use SUMPRODUCT (avoid using whole columns for that) or an array with OFFSET like this:
=SUM(COUNTIFS(Orders!D:D;"*Ecolab*";Orders!B:B;">=01/01/2019";Orders!U:U;">=36";OFFSET(Orders!J:J;0;{1;2;3;4;5;6;7});">=1"))
If the count for K:Q should be 1 when there may be more than one cell greater or equal to 1 in a single row then you need to apply OR criteria in a SUMPRODUCT.
SUMPRODUCT formulas should not use full column references; there is too much wasted calculation. The following is for rows 2:99; adjust for your own use.
=SUMPRODUCT(--ISNUMBER(SEARCH("ecolab", Orders!D2:D99)),
--(Orders!B2:B99>=DATE(2019, 1, 1)),
--(Orders!U2:U99>=36),
SIGN((Orders!K2:K99>=1)+(Orders!L2:L99>=1)+(Orders!M2:M99>=1)+(Orders!N2:N99>=1)+(Orders!O2:O99>=1)+(Orders!P2:P99>=1)+(Orders!Q2:Q99>=1)))
I am trying to make this work:
=SUMIF(MATRIX!$B$2:$B$36,"YES",B5:AJ5)
Note that the range is a COLUMN and the sum range is a ROW but when the formula computes it doesn't sum the Row B5:AJ5 it actually sums B5:B40. What do I need to add to have it sum the ROW and not the COLUMN.
EXAMPLE:
As you have discovered, a SUMIF expects both the criteria array and the sum array to be both rows or columns but not one of each. You have correctly used the same number of cells in each; the problem is that they are in different directions. A TRANSPOSE function can reverse the direction that the outer function 'sees' the one of the arrays but you need to change from SUMIF to SUMPRODUCT and enter it as an array formula with Ctrl+Shift+Enter.
=SUMPRODUCT((B$2:B$5="yes")*(TRANSPOSE($H2:$K2)))
When entered correctly with CSE, the result in L2 is 2.3. Fill both right and down for something resembling the following.
I don't believe you can use transpose with SUMIF but someone might know a trick to it.
I'm trying to average the largest (or smallest) N values in a range that are non zeros. Say my data is on column A, I am using this formula:
=AVERAGE(SMALL(A:A,{1,2,3}))
which averages the three smallest values in A. A similar formula can be used with LARGE in place of SMALL, for the largest values. How can adapt the formula to find the smallest (largest) N values that are non zero, and average only those? I probably have to play with array formulas, IFs, and "<>0", but I'm not very familiar with the excel syntax.
Many thanks in advance!
If all the numbers are zero or greater, check for the number of values that are zero, and start your SMALL above them:
=AVERAGE(SMALL(myRange,{1,2,3}+COUNTIF(myRange,0)))
IF some values might be less than zero, then
=AVERAGE(SMALL(IF(A:A<>0,A:A),{1,2,3}))
entered as an array formula by holding down CTRL + SHIFT while hitting ENTER.
Let's say I'm trying to count the number of rows where the value in column A is greater than in column B and the data I have is that A1 to A10 has the numbers 1 up to 10 and B1 to B10 has the numbers 10 down to 1.
The forumula I've constructed is
=COUNTIF(A1:A10, ">"&B1:B10)
The correct result would be 5 but if I place this formula in row 10 I get the result of 9. Also, I get different results if I place this exact same function in different cells.
It seems to be the cell references as the second parameter that breaks the function as something like =COUNTIF(A1:A10, ">4") works fine.
Countif accepts a single condition so if you place that formula to third row, it will compare the array to B3; if you place it to 7th row, it will compare the array to B7.
You can try the following formula:
=SUMPRODUCT(--(A1:A10>B1:B10))
It will compare the arrays elementwise and return boolean values. -- ensures those boolean values are converted to 0's and 1's. And it sums them up at the end. This function normally takes the multiplication of several arrays (hence the name sumproduct) but here we are using it on only one array to make use of its ability to work on arrays element-wise. You can give other conditions as well:
=SUMPRODUCT(--(A1:A10>B1:B10), --(A1:A10<4))
I'm having an issue getting accurate data from the SUMIF function. This appears to be caused by the SKU and Product name being identical however I don't understand why the selected range would be ignored.
SUMIF(G:K,A2,K:K) - Cell D2 is calling for the sum of K yet returning the sum result of K2:M2. All other results in D are correct.
SUMIF(G:K,A2,I:I) - If I change the formula in D to SUM I:I (text not a numeric field) the function returns the sum of K:K
Example file http://tempsend.com/013C2B6378
According to the documentation here the range to be summed starts at the top left of the sum range (K:K in your first example) but its size is given by the size of the criteria range (G:K in your example). So I think that's why you're getting extra columns summed in your result.
If you have multiple criteria involving different columns, you should be able to use SUMIFS.
So let's say your data sit in 8 rows (including the headings).
then you simply need to change your formula to say, look for B2 in column G OR in I, if true, then sum the values in K. Right?
put this formula in B2 and press ctrl+shift+enter to calculate the formula.
=SUM(IF(($G$2:$G$8=B2)+($I$2:$I$8=B2),1,0)*$K$2:$K$8)
then drag and fill down until the last cell.
obviously you need to adjust the ranges in the formula to adapt to your own data.
tell me if you get to the answer via this.