Word Count

LtVVaughn

New Member
Joined
Sep 7, 2006
Messages
17
I am trying to find the number of times specific words occur in a column. For instance, I am serching for "visit" and "call" (not case sensitive) within a column. These words may occur more than once in a particular cell of the column and I need to count each time these words occur, not a count per word, but count the times both words occur in cells in the column.

Thanks in advance!
 

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
just for fun
Source1st2nd
Rawcallvisittotalcallvisittotal
Call me before your visit don’t visit me before call Me549549
Visit visit call call call

Power Query:
//1st
let
    Source = Excel.CurrentWorkbook(){[Name="Table21"]}[Content],
    Lower = Table.TransformColumns(Source,{{"Raw", Text.Lower, type text}}),
    Split = Table.ExpandListColumn(Table.TransformColumns(Lower, {{"Raw", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Raw"),
    Contain = Table.SelectRows(Split, each Text.Contains([Raw], "visit") or Text.Contains([Raw], "call")),
    Count = Table.Group(Contain, {"Raw"}, {{"Count", each Table.RowCount(_), type number}}),
    Pivot = Table.Pivot(Count, List.Distinct(Count[Raw]), "Raw", "Count", List.Sum),
    Total = Table.AddColumn(Pivot, "total", each [call]+[visit])
in
    Total
Power Query:
//2nd
let
    Source = Excel.CurrentWorkbook(){[Name="Table21"]}[Content],
    Lower = Table.ToColumns(Table.TransformColumns(Source,{{"Raw", Text.Lower, type text}})),
    C2T = Table.FromList(Lower, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Ren = Table.RenameColumns(C2T,{{"Column1", "Raw"}}),
    Extract = Table.TransformColumns(Ren, {"Raw", each Text.Combine(List.Transform(_, Text.From), " "), type text}),
    call = Table.AddColumn(Extract, "call", each List.Count(Text.Split([Raw],"call"))-1),
    visit = Table.AddColumn(call, "visit", each List.Count(Text.Split([Raw],"visit"))-1),
    total = Table.AddColumn(visit, "total", each [call]+[visit]),
    TSC = Table.SelectColumns(total,{"call", "visit", "total"})
in
    TSC
 

Some videos you may like

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Watch MrExcel Video

Forum statistics

Threads
1,127,107
Messages
5,622,782
Members
415,927
Latest member
vedasinternational

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top