using OR within a sumproduct - excel

I have a table:
a 1
b 2
c 3
and I want to use a SUMPRODUCT that will give me the total if the cell is a or b.
I have a cell that shows:
a/b
and I want to use either SUMIF or SUMPRODUCT to give me the total if it is a or b.
I wrote this:
=SUMPRODUCT(--(A2:A4=LEFT(A7,1)))
Do you think there is a way to use an OR within the SUMPRODUCT so that it can check for b within the table and give the total of that?

In a SUMPRODUCT formula OR is +. AND is *
=SUMPRODUCT(--(A2:A4=LEFT(A7,1))+(A2:A4=LEFT(B7,1))

Related

SUMIF but for products?

I have a table like the following:
X 1
X 3
X 2
Y 2
Y 5
Z 3
Z 4
I know I could use SUMIF to calculate the sum of the second column for each value in the first column, e.g., =SUMIF(A1:A7,"X",B1:B7) would give me the sum of values for X: 1+3+2=6. However, I want the product of values in the second column for each value in the first column. I.e., the output would be:
A 6
B 10
C 12
When I try to search for SUMIF but for product, I only see suggestions to use SUMPRODUCT, but that multiplies arrays together and then adds their values, whereas I don't want to sum anything, just multiply all the values within a column.
My only idea is to create a new column with the log of the values, then do EXP(SUMIF(...)) to get the product. However, this will not work if any values are 0 or negative. Is there any way to directly compute the product I want?
If one has the Dynamic Array formula FiLTER:
=PRODUCT(FILTER(B1:B7,A1:A7="X",0))
You can also use a Pivot Table:
There are probably cleverer* ways, but you could use this array formula:
=PRODUCT(IF($A$1:$A$7=D1,$B$1:$B$7))
*Edit - as I said, see Scott's answer. I always forget the new formulas.

EXCEL Formula: Multiply SUMIFS outcome with the corresponding row value from a different column

I am trying to use SUMIFS and multiply its output with the a values from the corresponding row. Example:
Example
In This example I will use just 1 criteria for the SUMIFS, but the concept remains the same:
SUMIFS(C2:C5; B2:B5; "=Sum"). This would return 5 + 6 = 11
Now I want to multiple that by the corresponding probability. Meaning 5 * 50% + 6 * 20%: SUMIFS(C2:C5; B2:B5; "=Sum") *
Any idea how to include the probability in the equation?
Thanks!
You can't use SUMIFS for this unless you add a helper column - try using SUMPRODUCT instead
=SUMPRODUCT((B2:B5="Sum")+0;C2:C5;D2:D5)
SUMPRODUCT multiplies all the arrays/ranges and then sums the result, so we can include your value and probability ranges with a conditional array based on "Sum" in the include range
With a helper column you can just use column E to multiply C and D, e.g. this formula in E2 copied down
=C2*D2
and then use SUMIFS like this
=SUMIFS(E2:E5;B2:B5;"Sum")

Formula to sum items in a column only if other column has specific value

I have an excel table with 2 columns. First column contains a string such as A,B,C and second column contains numbers. I want to obtain sum of numbers in each row if text of first column for that row is equal to given text.
For example:
A 2
C 3
B 4
A 1
C 3
formula(A) = 3
formula(B) = 4
formula(C) = 6
and so on.
One way to achieve this is via SubTotal option. Follow the example in this link Creating subtotals
Another way to do the same is using sumif function follow this link Sumif function
SUMIFS() is capable of doing this. As is SUMPRODUCT()
In european excel this would look like this. I don't know where your reference is so I am putting it in a cell named Reference.
SUMIFS($B:$B;$A:$A;"="Reference)
If you want a "running" count, then replace the arrays - from $B:$B to B$2:B2 and similar with $A:$A, and copy it down the rows.

Count with criteria for changing column in excel

I have a data looks like this:
a b c
1 3 4
2 3 3
4 1 2
2 4 2
In another worksheet, I want to do the following calculation:
whenever A1 returns a (header of data worksheet), count number of items that are smaller and equal to 2 in column "a". (result will be 2)
if A1 returns b, count number of items that are smaller and equal to 2 in column "b". (result will be 1).
A1 has already been preset with formula such that it will show a or b or c as conditions changed.
I need the formula to be lean... I actually have 6 headers, so if I keep on using if functions, I will probably have to set 6 if functions in one cell...that can be overwhelming. index match cannot provide a range to work on...Any suggestion? thanks
I don't know vba. If you could provide a workable vba code, i don't mind. but i don't know how to read it...>.< please provide user manual for that. lol, thank you~
If your data is found on Sheet1 and the a is found on column a, b is found on column b etc. enter this formula on then next sheet on b1 when a1 is the column value:
=COUNTIF(INDIRECT("Sheet1!"&a1&":"&a1),"<=2")
The Indirect is for adding text to your reference.
If your data sheet is Sheet1, you could try the array formula:-
=SUM((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Must be entered with CtrlShiftEnter
(actually there are 3 items less than or equal to 2 in column A)
Or you can use the SUMPRODUCT version if you prefer not to use an array formula:-
=SUMPRODUCT((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Or you can use this INDEX/MATCH method which is probably more efficient:-
=COUNTIF(INDEX(Sheet1!A2:C5,,MATCH(A1,Sheet1!A1:C1,0)),"<="&2)

How do you add two COUNTIF equations together?

How do i add two COUNTIF equations together to get a total
I assume you only want to count when the list contains both items in the same position.
Example
A1: =a B1: =a
A2: =a B2: =b
A3: =a B3: =c
COUNTIF(A1:A3,"a") returns 3
COUNTIF(B1:B3,"b") returns 1
to count where first list =a and second list =b you can use SUMPRODUCT, which would return 1.
SUMPRODUCT((A1:A3="a")*(B1:B3="b"))
Or you could use an array formula. You need to use CTRL+SHIFT+ENTER when commiting the formula rather than a simple ENTER. This will automatically add { } around the formula.
=SUM((A1:A3="a")*(B1:B3="b"))
Working on Andy Pope's example (if this is what you want):
=COUNTIFS(A11:A13,"a",B11:B13,"b")
Combining this with your other question, do you mean?
=(COUNTIF(B3:L3,"X")*20)+(COUNTIF(N3:O3,"X")*2.5)
That would add 20 for every X between B3 and L3 and 2.5 for every X in N3 or O3.
If you want to add the count of two different occurences in one column or row...for example:
How often did customers call my store looking for either flour or sugar, where flour and sugar are typed into the cell.
Here is the formula:
=SUM((COUNTIF([Cell Range],"flour")),(COUNTIF([Cell Range],"sugar")))
The cell range can also be an entire column (that's what I did). I just clicked on the column when it asked for range.
If you count particular value, you can use COUNTIF function,
Example,
A B
0-5 A
6-10 B
11-15 C
0-5 D
16-20 E
21-25 D
0-5 A
21-25 D
=COUNTIF(A1:A8,"0-5")
If you count Multiple function,
=COUNTIFS(A1:A8,"0-5",B1:B8,"A")
=SUMPRODUCT(COUNTIF(A:A,{"Text1","text2","text3","text"}))
You can extend this by adding more csv and it will add up the count of all values if exist in column A. Change the range according to your requirement.

Resources