Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Dee
Helper III
Helper III

How to count number of words in a column and not character

Hi all,

 

I am trying to find the number of names in a column and not the actual characters.

eg

John Doe = 2

 John Doe = 7

 

Is there dax for a word in a text count and not only characters?

 

TIA

5 REPLIES 5
mahoneypat
Employee
Employee

In case it helps, it is also possible to do this in query with M code too.  For example,

 

List.Count(Text.Split("John Doe", " "))  would equal 2.  You would use your column name in place of "John Doe".

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Greg_Deckler
Super User
Super User

So, potentially, this is the way I do these kinds of things:

 

Words Column Counter = 
  VAR __Length = LEN('Table'[Column])
  VAR __Text = SUBSTITUTE('Table'," ","")
RETURN
  __Length - LEN(__Text)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler I seem to get an error with the following message:

 

 The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

@Dee My bad, I corrected it below. Also included measure form.

 

Words Column Counter = 
  VAR __Length = LEN('Table'[Column])
  VAR __Text = SUBSTITUTE('Table'[Column]," ","")
RETURN
  __Length - LEN(__Text)

Words Column Measure = 
  VAR __Length = LEN(MAX('Table'[Column]))
  VAR __Text = SUBSTITUTE(MAX('Table'[Column])," ","")
RETURN
  __Length - LEN(__Text)

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
harshnathani
Community Champion
Community Champion

@Dee ,

 

Please watch the below video by @ruthpozuelo .

 

It separates your name into two separate column using DAX. 

 

In your case you can just count the no. of space between words to get the total words.

 

Regards,

Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.