I have a table like below:
12/7/2012 A B
100
12/21/2012 A I
20
12/23/2012 A I
25
12/1/2013 A I
20
12/1/2014 A I
20
I want to get the value in column D where column B is "A" and column C is "I". I used a sumproduct to get the value in column D, but I need to go down 1 row from wherever column B is "A" and column C is "I". This is my formula:
=SUMPRODUCT(--(B:B="A"),--(C:C="I"),F:F+1).
It should return a value of 85, but it returns a value of 4.
You could use
=SUM((B1:B10="A")*(C1:C10="I")*(D2:D11))
as an array formula with CtrlShiftEnter
or
=SUMPRODUCT(--(B1:B10="A"),--(C1:C10="I"),(D2:D11))
and extend the range as far as you need to.
What happens with your formula
=SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1)
is that it is just adding one to each row in column D. D1, D3, D5 and D7 are empty cells so count as zero. So for the four matching rows it is adding one to the total and the result is 4.
If =SUMPRODUCT(--(B:B="A"),--(C:C="I"),D:D+1) worked it may just be coincidence. You might check by taking a copy and in that deleting D1 with Shift cells up then applying:
=SUMIFS(D:D,B:B,"A",C:C,"I")
Or of you don't have SUMIFS filter to delete rows that do not contain a date in ColumnA, A in ColumnB and I in ColumnC, then summing ColumnD.
With SUMIFS an alternative to #Tom's SUMPRODUCT might be:
=SUMIFS(D2:D1000001,B1:B1000000,"A",C1:C1000000,"I")
Related
How can I CONCAT two columns values while the column A has similar values in each rows in Excel?
Something like following, what I need is to CONCAT values of rows in Columns B and C while the A is similar:
Assuming you are on Excel 365 and have use of FILTER() and TEXTJOIN(), you can enter the following formula into column D and drag down:
=IF(COUNTIF($A$1:A1,A1)=1,TEXTJOIN(":",TRUE,FILTER($B$1:$C$15,$A$1:$A$15=A1)),"")
This checks if the value in column A is the first occurrence of that value. If it is, it will output a colon delimited string of every value in columns B:C where col A equals the current value in column A.
you can use if command
if cellA1<>cellA2 then you concatenate b2 and C2
else you concatenate D2 and B2, and C2.
You can use a helper column to do this but you need to have a header row for this to work. Assuming your first row of data is in A2, B2, C2:
paste this into D2:
=IF(A2=A1,D1&","""&B2&""":"""&C2&"""",""""&B2&""":"""&C2&"""")
and paste this into E2:
=IF(A2=A3,"",D2)
Copy these two down to every row in the data.
Note: This version puts the concatenated result in D at the last row of the group instead of at the first row of the group like your screenshot shows.
I am trying to subtract certain cells from 1 single master cell, if other cells contain a certain string.
For example: Cell B2 will be the master with a total dollar amount.
Now, if any row in column C were to contain "text" I want to subtract the number in the same row, but in column D, from B2.
Ergo, if C3 has "text" and D3 has "3", subtract 3 from B2.
My problem is that I don't even know where to start. How do you get a formula to iterate through rows? How do you get that formula to assign the same row to the C and D operations?
If the original formula in B2 was:
=SUM(A:A)
then replace it with something like:
=SUM(A:A)-SUMPRODUCT(--(C:C="text")*(D:D))
I have the following Excel spreadsheet:
A B Desired Result Column B
1 Product A 50 **50** **50**
2 Product B =IF(A2="","",B1) 50 50
3 =IF(A3="","",B2)
4 Prodcut C =IF(A4="","",B3) 50 **40**
5 =IF(A5="","",B4)
6 ="" =IF(A5="","",B5)
7 Product D =IF(A5="","",B6) 50 40
8 Product E =IF(A5="","",B7) 50 40
** Input of User
In Column A there is a list of different products. As you can see there can either be empty cells or cells with formula ="".
In Column B I want to achieve that the last value before the first empty cell or ="" cell applies to the other rows.
For example: If I enter a 50 in Cell B1 I want to achieve that this 50 appears next to every product and empty cells or ="" are ignored.
I can achieve this with the following formula:
=IF(A2="","",$B$1)
Now the problem is, that the user can also type a different number in another cell in Column B. For example he could type in a 40 in Cell B4.
In this case I want that the 40 applies to all other following rows instead of the 50 as you can see in the section "Desired Result Column B" in the example above.
How do I have to change my formula in Column B to achieve this?
Enter the following formula in Cell B2
=IF(A2<>"",INDEX($B$1:$B1,MAX(IF($B$1:$B1<>"",1,0)*ROW($B$1:$B1))),"")
Drag/Copy down as required.
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Try:
B2: =IF(A2="","",LOOKUP(2,1/LEN($A$1:A1),$B$1:B1))
With the addressing mode used in the LOOKUP formula, it will examine the rows up to the row before the lookup. If the column A value is not blank, lookup_vector will match the last non-blank cell in column A prior to the row containing the formula, and result_vector will return the value in the same row in column B.
It is rather critical that your user entries are restricted as you have described above.
If the user can make an entry in column B that does NOT correspond to an entry in column A, and you want that entry to be copied down, then use:
=IF(A2="","",LOOKUP(2,1/LEN($B$1:B1),$B$1:B1))
Also, note that the sequence will be upset if the user deletes an entry in column B, instead of replacing it with another number. The formulas below the deletion will interpret the deleted value as a zero.
Take a look at the screenshot:
I am trying to count in column B the number of checked boxes (with TRUE value) in columns ABSENT and the same thing in column C for LATE.
Is there any simple way I can do it?
Thank you,
Pawel
You can use the COUNTIFS function for this. Put the following formulas in the indicated cells:
B4
=COUNTIFS(D$2:ZZ$2, "ABSENT", D4:ZZ4, TRUE)
C4
=COUNTIFS(D$2:ZZ$2, "LATE", D4:ZZ4, TRUE)
You can copy these cells down the B and C column to apply the same formula there.
This is what happens in B4:
The columns D to ZZ are scanned for the combination of the following two conditions:
row $2 has the value "ABSENT"
row 4 (the same row as where the formula is) has the value true
The columns are counted where both of these conditions are true.
How to solve this case:
Suppose there are two columns having same text assigned with values then i need to subtract those values to get the result in a new cell
For eg: if james in cell a1 has been assigned value as 20 in cell b1 and also james in cell c2 has been assigned value as 40 in cell d2, then i need to get the result as (40-20=20) in a different cell such that while giving the formula the James in cell a1 and c2 has to be same and only there corresponding values get subtracted and not with any other cell.
Please help me on this.
I find it a little strange that you would be starting with C and subtracting A, but okay. If what you are doing is looking for a name in C and taking the number in the right column then subtracting that from the value to the right of the same name in A, then VLookup has you covered:
=VLOOKUP("james",C:D,2)-VLOOKUP("james",A:B,2)
You can also use a formula based on INDEX and MATCH, which doesn't require cells to be sorted (as VLOOKUP does):
=INDEX(B:B; MATCH("James";A:A;0)) - INDEX(D:D; MATCH("James";C:C;0))
If either A:A or C:C doesn't have a "James", then the formula will return #NA. You can avoid this by adding a conditional to check whether the match is valid.
For example, if column C might not contact "James", replace
INDEX(D:D; MATCH("James";C:C;0))
with:
IF(ISNA(MATCH("James";C:C;0)); 0; INDEX(D:D; MATCH("James";C:C;0)))
which will then return 0 if there is no James in column C, otherwise the corresponding value in column D will be returned.