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

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.

Related

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

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.

How to do multi-column match in Excel

I have a spreadsheet that looks like this:
A B C D
------------------------------------
1 | Yes | No | | | |
2 | 1 | 1 | 0 | 1 | 0 |
------------------------------------
------------------------------------
12| Yes | No | | Yes | Yes |
13| Yes | Yes | No | No | |
14| Yes | No | | No | Yes |
15| No | Yes | No | No | |
...
I want to fill the cells in Row 2 with a 1 or 0 depending on several criteria. The value should be 1 if all of the following are met (using cell D2 as a reference):
All previous values in Row 1 should match at least one entry in the table starting at D12. For cell D2, this means A1:C1 should exactly match columns A:C in at least one row of the table.
For any of the matching rows from #1, there should be a non-empty value in the same column as the cell being evaluated. So cell D2 would look for a non-empty value in Column D of any rows that match the criteria in #1.
If either of these conditions fails, the cell value should be 0. In Cell D2 we have a value of 1 because the algorithm finds a match in rows 12 and 14 and a non-empty cell in D12 and D14.
I'll need to be able to apply this dynamically across several columns so I'm trying to avoid writing a column-specific function. I realize I could probably write a UDF to perform this, but I wanted to avoid going that route if possible.
Because this was a challenge I had a go at it and came up with
=SIGN(SUM(--(MMULT(($A1:A1=$A12:A15)*(B12:B15<>""),TRANSPOSE(COLUMN($A12:A15)^0))=COLUMNS($A1:A1))))
to be entered in B2 and pulled across. This has to be entered as an array formula using CtrlShiftEnter
A2 I think is just
=sign(counta(a12:a15))
because it will be 1 unless the whole column is empty.
I'm not sure there's a complete answer to your problem as stated without a UDF, but I'd question the method a bit and say "why complicate with 'AND this column isn't blank (but could be any other value)?"
Why not just look for a row match from that field backward? Seems to me it would just shift things by a column, and in fact, this is exactly what you're doing in A2 anyway, since there's nothing before A. So matching on duplicate rows for example, D2 would contain basically the same information as your example has in C2.
To look for duplicates across fields, you could use something like this formula that would go in C2: =IF(SUMPRODUCT((A3:A15=A1)*1,(B3:B15=B1)*1,(C3:C15=C1)*1)>1,1,0)
In D2, you'd copy that formula and add (D3:D15=D1)*1, etc.

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

Find two matching rows and display data from the thirt one (Excel)

So i have Two Sheets.
First sheet contains two columns
BRAND | LEFTOVER
The second sheet consists of two columns also.
BRAND | LEFTOVER (%)
So in case if the BRAND row value in the first Sheet will match the BRAND row value in the second i want to display the matching LEFTOVER (%) row value in the first sheet rows in the column LEFTOVER.
Kind of lost here.
Appreciate any ideas. Thanks.
In Sheet2:
. A | B
--------------------
1 BRAND | LEFTOVER %
2 X | Y
3 |
In Sheet1:
. A | B
--------------------
1 BRAND | LEFTOVER
2 X | =VLOOKUP(A2,Sheet2!A:B,2)
3 |
The VLookup function searches for its first parameter (in this case the value of Sheet1!A2) in the first column of the range denoted by the second parameter (in this case the leftmost column of the range containing columns A and B on Sheet2)
It then returns the value from that same row of the range that is to the right in the columns denoted by the third parameter (1 is the leftmost column where the matched value was). So in this case we use the number 2 because 1 means column A and 2 is column B (which explains why we used a two column wide range for the second parameter - it needed to encompass the column the result was in)
This isn't the only way to do this, but it is the easiest.
As Jerry stated VLOOKUP is the simplest way to do this.
HOWEVER if you have multiple/repeat instances (rows) in BRAND, VLOOKUP will only return the first record (row) that appears in your data.
If this is the case, you will need to add either a unique identifier column; and/or additional criteria to differentiate between the repeat instances.
As an example column A is used as a unique identifier to differentiate between the 2 'Nike' rows.
A B C
1 BRAND LEFTOVER
2 Nike 50
3 Adidas 25
4 Reebok 30
5 Nike 29
I feel that you can use vlookup to accomplish your goals.
Let me explain it in a bit detail.Suppose you have two sheets as:
A | B | A | B
--------------------- | -------------------
1 BRAND | LEFTOVER % | 1 BRAND | LEFTOVER
2 X | Y | 2 X | =Vlookup(A2,Sheet2!A:B,False)
3 | | 3 |
Sheet2 | Sheet1
After this you can drag this formula for the entire range. This will automatically make the formula correct for the below cells as well.
Also, if you need to populate any other fields from the Sheet2 then you can also use the vlookup as an array formula like: VLOOKUP(A2,Sheet2!A:B,{1,2,3,4},FALSE)
Enter this as an array formula using Crtl+Shift+Enter
Here {1,2,3,4} stands for the columns to be fetched.
If you want to know more about vlookup then read this article: http://www.exceltrick.com/formulas_macros/vlookup-in-excel

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