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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
UNOFOR
Frequent Visitor

How to count the number of words in a table

Hi

 

How do I count the words (not rows) in a specific table or column if there is more than one word in each cell.

PBI fråga.png

Best

/Uno

 

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

It would be good if you could mark the post as the solution if it has solved your problem. 

 

Thanks.

 

Best

Darek

View solution in original post

Hi. Of course I will. (as soon as I figured out how)

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

DAX is not the right tool to deal with this. Use Power Query. I'm not even sure it's possible. If it is, it'll be extremely hard.

 

Best

Darek

Ok, thanks anyway

Anonymous
Not applicable

If you really need it in DAX, then here it is:

 

[Word Count] =
var __selectedWord = SELECTEDVALUE( TableWithIndividualWords[Name] )
var __selectedWordLength = LEN( __selectedWord )
var __wordCount =
	SUMX(
		YourTable, -- this table will honor any filters you put on it 
		var __name = YourTable[Name]
		var __nameLength = LEN( __name ) 
		var __wordCountInRow =
			( __nameLenth - LEN(SUBSTITUTE( __name, __selectedWord, "")))
				/ __selectedWordLength
		return
			__wordCountInRow
	)
return
	__wordCount

But to get this working you have to have a table that stores all the possible words you could encounter in advance. And the table should stand on its own, without any relationships to any other table. I named the table TableWithIndividualWords and it has only one column [Name] where you store all the possible words. To make this into a visual table you just drag the column from the table so that individual words are visible and drop the measure. It'll calculate the number of times the word appears anywhere in the first table (YourTable).

 

Best

Darek

Thank you vary much. 


@Anonymous wrote:

If you really need it in DAX, then here it is:

 

[Word Count] =
var __selectedWord = SELECTEDVALUE( TableWithIndividualWords[Name] )
var __selectedWordLength = LEN( __selectedWord )
var __wordCount =
	SUMX(
		YourTable, -- this table will honor any filters you put on it 
		var __name = YourTable[Name]
		var __nameLength = LEN( __name ) 
		var __wordCountInRow =
			( __nameLenth - LEN(SUBSTITUTE( __name, __selectedWord, "")))
				/ __selectedWordLength
		return
			__wordCountInRow
	)
return
	__wordCount

But to get this working you have to have a table that stores all the possible words you could encounter in advance. And the table should stand on its own, without any relationships to any other table. I named the table TableWithIndividualWords and it has only one column [Name] where you store all the possible words. To make this into a visual table you just drag the column from the table so that individual words are visible and drop the measure. It'll calculate the number of times the word appears anywhere in the first table (YourTable).

 

Best

Darek

 

Wow, thanks. I guess the sentence "stores all the possible words you could encounter in advance" will be the thing that makes it hard to use. Seems quite easy but appearently it is not. The problem occured when hade created a word map and wanted to creat a slicer from the words accouring in it.

 

So you advice would be to instead create a separate table "by hand" using excel?

 

/U


 

Anonymous
Not applicable

This might be better: https://www.youtube.com/watch?v=YOmL57g3RMg

 

Best

Darek

Aaah, there it is!!

 

Thank you very much!

 

/U

Anonymous
Not applicable

It would be good if you could mark the post as the solution if it has solved your problem. 

 

Thanks.

 

Best

Darek

Hi. Of course I will. (as soon as I figured out how)
Anonymous
Not applicable

This might help you:

 

https://www.youtube.com/watch?v=HPDG_KXiLBo

 

Best

Darek

Ok, I will give it a try even if it´s a bit above my level.  Your help is much appreciated.

 

Thanks a lot

 

/U

Anonymous
Not applicable

Hi there.

 

Mate, the last link I sent you shows you exactly how to obtain a table with all the distinct words that you can find in your table. Please follow it and you'll have the table I was talking about. Then everything is very simple.

 

Best

Darek

Anonymous
Not applicable

No. My advice is to extract all individual words from the table using Power Query. This is the right tool to do it. Not Excel.

 

Best

Darek

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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