I'd like to know if there's a way to calculate two countifs with different data and criteria in a single formula (not row by row or with pivot tables). Let the following example apply:
I have the following table: fields A, B and C for each item (ID). Table header starts in cell T1.
I'd like to know how many items have 2 or more fields (A, B, C) with a number greater than 5.
I'd create another column X and use the following formula row by row: (Example for row 2)
=COUNTIF(U2:W2;">5")
and for that new column X (with all the COUNTIF formulas) I would use another COUNTIF
=COUNTIF(X:X;">1)
Is there a way to concatenate both? (I guess with an array formula)
Thanks in advance!
Try
=SUMPRODUCT((((U2:U11>5)+(V2:V11>5)+(W2:W11>5))>1)*1)
or
=SUMPRODUCT(--(((U2:U11>5)+(V2:V11>5)+(W2:W11>5))>1))
You can also use SUM(IF()) as an array formula like below
=SUM(IF(((U2:U11>5)+(V2:V11>5)+(W2:W11>5))>1, 1, 0))
Above being an array formula needs to be committed by pressing Ctrl+Shift+Enter.
Related
I have a table with a target sum column (ColA) and three columns to filter based on criteria. I've been using SUMIFS to calculate the sum of ColA based on the criteria columns Cols B through D however I notice I'm not doing this correctly.
One thing to note is that the criteria columns have varying amounts of criteria each (e.g. column B has more OR conditions than C)
My current formula is:
SUM(SUMIFS(table[ColA], table[colB], {"val1", "val2", "val3"}, table[colC], {"val1", "val2"}, table[colD], {"val1", "val2", "val3", "val4"}))
The result of this formula is incorrect after manually checking the sum in the underlying table. Any advice on how to sum a column based on a set of multiple OR values?
You will need to do a SUMPRODUCT which will get long:
=SUMPRODUCT(table[ColA]*
((table[colB]="val1")+(table[colB]="val2")+(table[colB]="val3")>0)*
((table[colC]="val1")+(table[colC]="val2")>0)*
((table[colD]="val1")+(table[colD]="val2")+(table[colD]="val3")+(table[colD]="val4")>0))
To understand, the * is the equivalent to AND, the + is equivalent to OR
Let's say your table is called Table1, starts in A1 with headers, and is 4 columns wide. In a cell somewhere to the right, let's say G2, you could enter this formula:
=AND(OR(B2={"val1","val2","val3"}),OR(C2={"val1","val2"}),OR(D2={"val1","val2","val3","val4"}))
leaving G1 blank, then your sum formula is just:
=DSUM(Table1[#All],1,G1:G2)
You could also break the criteria formula up into three cells, one for each column, using:
=OR(B2={"val1","val2","val3"})
=OR(C2={"val1","val2"})
=OR(D2={"val1","val2","val3","val4"})
in G2:I2 (either leave G1:I1 blank, or give them labels that do not match any of your table headers), then use:
=DSUM(Table1[#All],1,G1:I2)
You could try to use MATCH() nested in SUMPRODUCT():
Formula in F1:
=SUMPRODUCT(ISNUMBER(MATCH(B2:B6,{"Val1","Val2","Val3"},0)+MATCH(C2:C6,{"Val1","Val2"},0)+MATCH(D2:D6,{"Val1","Val2","Val3","Val4"},0))*A2:A6)
I need to create a formula in excel that returns the sum-product of two columns in a range, based on two conditions.
Considering a table of 4 columns (A;B;C;D), if any row in column A is equal to a given value (example="A") and any row in column B starts with "*", then multiply column C and D and sum these products.
Any suggestions on how to implement the formula?
I thought it could be the following formula but it doesn't work:
=SUMPRODUCT(--(A2:A12="A"); --(left(B2:B12;1)="*"); C2:C12; D2:D12)
You could use an array formula such as :
{=SUM((A2:A12="A")*(LEFT(B2:B12)="*")*C2:C12*D2:D12)}
Remember to validate with ctrl+shift+enter
I've been using Excel's COUNTIFS function to count the number of rows in a table that meet certain criteria, E.g:
=COUNTIFS(Table1[Result],"Fail", Table1[Comments], "")
Now I want to modify this expression so that it only counts rows in Table1 that are visible. (I.E. Not filtered out.) How can I accomplish this?
Simple way is to add another column to table - e.g. called helper with a formula like this
=SUBTOTAL(103, B2)
where column B is Result column
Now change formula to
=COUNTIFS(Table1[Result],"Fail", Table1[Comments], "",Table1[Helper],1)
the subtotal formula only returns 1 on visible rows
Without a helper column you can use this formula
=SUMPRODUCT((Table1[Result]="Fail")*(Table1[Comments]=""),SUBTOTAL(103,OFFSET(Table1[Result],ROW(Table1[Result])-MIN(ROW(Table1[Result])),0,1,1)))
I use this formula:
=subtotal(3,B2:B100)
where subtotal(3, that is CountA and
B2:b100 is the range.
The hidden rows in a filter are ignored and this formula only counts the visible rows.
It works for me and hope it works for you
Let's say,
Sheet1:A1 = x
Sheet2 contents look like
x 3 3 4
y 0 2 1
Is there an excel formula that could match Sheet1:A1 with Sheet2:A1 (basically the value 'x') and add the other cells in that row (3,3,4). The result (Sum='10') should get updated at Sheet1:C4 lets say.
I tried SUMIF but that shows the content of only one column due to the restriction that it can handle only the matchable array size. I know this can be achieved through VBA, but just wanted to know if a formula is available.
TIA!
This formula will do what you want:
=SUM(SUMIF(Sheet2!A:A,A1,INDIRECT("Sheet2!" & {"B:B","C:C","D:D"})))
It will iterate through the columns doing individual SUMIF() on each and then adding the results.
If you want more columns or different change the address in the array to the columns desired.
Try the following
=SUM(IF(Sheet2!A1:A99=A1,Sheet2!B1:D99,0))
Note that this is an array formula, so it must be entered using Ctrl+Shift+Enter.
What this formula does is converts any rows on Sheet2 without x in column A to zeros in B:D and then sums what is left.
Similarly, you could use
=SUMPRODUCT((Sheet2!A1:A99=A1)*Sheet2!B1:D99)
and you wouldn't have to enter it as an array formula.
For a non-volatile, non-array formula, try this
=SUM(INDEX(Sheet2!B:D,MATCH(Sheet1!A1,Sheet2!A:A,0),))
I have an Excel spreadsheet of the form:
A,B
X,1
X,5
Y,4
Y,11
X,7
Z,1
I would like to get the maximum value of column B for each distinct value of column A - how can I do it via pure Excel formula?
Desired result (order is irrelevant):
A,B
Y,11
X,7
Z,1
In other words, I would like Excel's version of an SQL query
SELECT A,max(B)
FROM myTable
GROUP BY A
Any version of Excel is acceptable, but I use 365 one.
Pivot tables are an acceptable approach (I currently did it with a pivot myself) but I would strongly prefer a real formula - the main goal of the question is to enhance my understanding of formula programming in Excel. No VBA
Gary's Student's answer is correct. I added a couple things.
Also, a link to the method:
http://blog.contextures.com/archives/2011/07/27/finding-min-if-or-max-if-in-excel/
A distinct list of values can be generated in a couple ways, here's one:
And here's links to a method or two for distinct lists. All with array formulas:
Ignore Duplicates and Create New List of Unique Values in Excel
Getting unique values in Excel by using formulas only
With data in columns A and B use the Array Formula:
=MAX(IF(A1:A6="x",B1:B6))
Same for "y" and "z"
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
Notice the braces in the Formula Bar
EDIT#1:
To generate the formulas automatically, first copy column A to column C.
Then use the Remove Duplicate feature in the Data tab:
Then enter the Array Formula in cell D1:
=MAX(IF(A$1:A$14=C1,B$1:B$14))
and copy down:
The formula is only entered once and then copied down!
Pivot table is the correct answer.
Select column A's title and drag it to the Row Labels section.
Select column B's title and drag it to the Values section.
Click the arrow on column B's title in the values section and choose Value Field Settings.
Select Max
Try below. Note I moved your desired output table to Columns D and E. You will not need to hard-code any values into formulas.
Data
D E
Y 11
X 7
Z 1
Formulas
E2 Formula: ={MAX(--($D1=A1:A6)*B1:B6)}
E3 Formula: ={MAX(--($D2=A2:A7)*B2:B7)}
E4 Formula: ={MAX(--($D3=A3:A8)*B3:B8)}