Using SUMIF on a range of columns or SUMPRODUCT to ignore text items - excel

I have a range with various text and numbers in them. I wish to total the numbers based on the identifying first column.
I have tried
=SUMIF(A1:A20,"John",B1:E20)
which only returns the first columns number. I've also tried
=SUMPRODUCT((A1:A20="John")*(B1:E20))
but as there is text in column C, it returns #VALUE!.
A | B | C | D | E
John | 5 | Wine | 2 | 7
Sean | 6 | Beer | 5 | 2
I want all of the numeric values in columns B-E to be totalled together when "John" is in column A

Here is an array formula solution - use Ctrl, Shift and Enter to confirm:
=SUM(IF(A1:A20="John",IF(ISNUMBER(B1:E20),B1:E20)))
If you just want to exclude column C you could use this non-array formula:
=SUMPRODUCT((A1:A20="John")*(B1:B20))+SUMPRODUCT((A1:A20="John")*(D1:E20))
Alternatively, perhaps move C so it's not in the middle of your numbers.

Try this formula:
=IF(A1="John", SUMPRODUCT(--(ISNUMBER(B1:E1)),B1:E1), "")
and drag down to get sum on each row.

Related

I have a list of keywords and want to count the number of match keywords in each cells text from EXCEL File

I have 2 sheet in a excel file. one is a Dictionary sheet and 2nd is a sheet containing a column of text. I want to match the dictionary keywords columns one by one and then the number of match keywords counts in each cell of the text column.
I have tried these formulas:
=(LEN(B2)-LEN(SUBSTITUTE(B2,Sheet1!A:A,"")))/LEN(Sheet1!A:A)
in this B2 is the first (start) cell of the text column and Sheet1!A:A is the dictionary column of other sheet.
but by this i get zero as a result
=(LEN(B2)-LEN(SUBSTITUTE(B2,Sheet1!A:A,"")))/LEN(Sheet1!A:A)
The result will be like this:
Text number_of_keyword_match | number_of_keyword_match using DIC col 2 | ........
using DIC col 1
1 any Text or sentence/sentences e.g match "3"
2 7
3 0
4 15
5 .................................................
7 .....................................................
.......................................................
..................................continue up to 2815 rows....
Assuming your text input looks like this:
| A |
-+----------------------+
1|apple apple beat beat |
2|apple beat beat carrot|
3|carrot apple apple |
and your dictionary looks like this:
| A | B |
-+-------+-------+
1|apple |beat |
2|beat |carrot |
3| | |
This formula will give you the count per word per cell of text
=(LEN(text!A1)-LEN(SUBSTITUTE(text!A1,dictionary!A1,"")))/LEN(dictionary!A1)
(In this example 2)
If I understand correctly, your expected output would be extra columns in the text sheet where each cell contains the sum of counts of each word in the corresponding column in dictionary, right? For example:
| A | B | C |
-+----------------------+---+---+
1|apple apple beat beat | 4 | 2 |
2|apple beat beat carrot| 3 | 3 |
3|carrot apple apple | 2 | 1 |
You can use array formulas to do this, starting with this one in cell B1:
=SUM(IFERROR((LEN(text!$A1)-LEN(SUBSTITUTE(text!$A1;dictionary!A:A;"")))/LEN(dictionary!A:A);0))
But instead of pressing Enter after pasting it in, press Ctrl+Shift+Enter to run it as an array formula. Then drag this formula down and to the right to get all the counts you want.
I would consider countif(), as an example:
=COUNTIF(Sheet2!A1:A10,Sheet1!A1)
which assumes your list starts in cell A1 on sheet1 and your text in cell a1 on sheet2.
To drag the formula as I showed it, without the data range moving you need :
=COUNTIF(Sheet2!A$1:A$10,Sheet1!A1)
if you put $ before the letters, then the columns don't move.

Excel function for comparing columns with repeated values

I'm using excel and have two columns (A & B) with values
I want to search for each value in Column A and return the position in Column B.
I'm using this formula:
IFERROR(MATCH("Values in Column A";"Array = Column B";0);0)
The results are:
Column A | Column B | Column C
1 | 4 | 2
2 | 1 | 3
3 | 2 | 4
4 | 1 | 1
1 | 2 | 2
| 3 |
It works fine if it doesn't encounter repeated values. However, I want it to encounter repeated values, so the formula should ignore the ones it was encountered before and go through the others. So the correct result should look like this:
Column C
2
3
5
1
4
Can you help me on this? Is there a VBA routine for this?
From the article Getting the 2nd matching value from a list using VLOOKUP formula, you can create a helper column to affix the instance number of each value, to create unique id's.
For example, in Column C, add the following function:
=A1&"-"&COUNTIF($A$1:A1,A1)
Note: The relative reference on the count range will cause the applicable range to grow as it is dragged down. The count of the items matching that cell in a range containing only that cell should always be one. As it gets dragged down to include other cells, it will increment accordingly.
Then add the same thing in Column D to get the instances of cells in Column B:
=B1&"-"&COUNTIF($B$1:B1,B1)
Finally, do the math you want to do in Column E like this:
=IFERROR(MATCH(C1,D:D,0),0)

Increment count in column based on value in column

I've 2 columns A and B. A contains names and B contains the count of those names till that record as shown below.
-----------------------------------
| A | B |
-----------------------------------
1 | Fruits | 1 |
2 | Flowers | 1 |
3 | Fruits | 2 |
So, want to have a formula for this. Expecting an array formula. Even if an array formula is not possible, a general formula
Attached a spreadsheet so that it can be explained better.
https://docs.google.com/spreadsheets/d/1wlWqdFwgv90s50iP-bXXBHciyualohj610qFiSatcmQ/edit#gid=1997586177
You do not need an array formula, and I would avoid them when possible. You can accomplish your task with
=COUNTIF(A$1:A1,A1)
Where A1 if the first value in the column of values you want to count. The $ allows you to anchor the top of your COUNTIF range while leaving the bottom dynamic.
In a google spreadsheet you may want to try:
=ArrayFormula(iferror(SORT(ROW(A1:A),SORT(ROW(A1:A),A1:A,1),1)-MATCH(A1:A,SORT(A1:A),0)-ROW()+2))
Example sheet

Excel, sum range split

I have a google spreadsheet and I want calculate to some data...
I want to sum the splits in a range
1 | A1 |
2 | 1Q1 |
3 | 3Q2 |
4 | 5Q7 |
I need the sum of the integers after the letter "Q" so in the example above I would get 1+2+7=10
This formula will do it all in one, just set the range in the formula , ie A2:A4
=SUM(VALUE((RIGHT(A2:A4,LEN(A2:A4)-FIND("Q",A2:A4,1)))))
Press CTRL+SHIFT+ENTER to enter the array formula.
You can use the function VALUE(RIGHT(text)) which will give you back the number value of the rightmost character in the string. Then use those values in your sum.
Assuming that the 3rd character is the number, you could try something like
=VALUE(MID(A:A,3,len(A:A)))
in column B
then sum that like this (for the 1st 3 rows):
=SUM(B1:B3)

Incrementing each row in excel that contains a number

I was sent an excel document in the following format:
A | B |
1 | abc |
| def |
2 | abc |
| def |
| ghi |
3 | abc |
| def |
So basically I have the first column which contains ordered numbers every couple of rows. I want to insert a row e.g. between 2 and 3, so that the new row will be numbered 3, and the rows below it are updated accordingly i.e. 3 becomes 4, 4 becomes 5 and so on.
I don't really use excel, but I am curious if there is there an easy way of doing this?
In A1, enter the following formula:
=IF(MOD(ROW(A1),2)=1,(ROW(A1)+1)/2,"")
And copy that formula down to the bottom of the range. Each time you insert a new row, you will need to manually copy the formula to the inserted row's first cell.
Is there a pattern in the b column, to distinguish if you need to jump to the next number?
if so use:
in cel A2 and further:
=IF(B2 = "abc",A1+1,A1)
With conditional formating, hide the repeating numbers: =A2=A1

Resources