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
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
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.

Top Solution Authors