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
Qotsa
Helper V
Helper V

Count the numbers in a text column

Hi,

 

I have a text column that contains values like -

 

Text Column

1,2,3,4,5

6,7

1,5,6

 

For above I would like to return -

5

2

3

 

Is there a way I can do a count of the numbers? Every number is always seperated by a comma.

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Qotsa 

create a calculated column

Column = 
PATHLENGTH(
SUBSTITUTE([Text Column];",";"|")
)

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Qotsa 

 

By the way, you might use STRING_SPLIT in Transact-SQL if necessary.

SELECT [Column1]
	, (
		SELECT COUNT(1) 
		FROM STRING_SPLIT([Column1], ',')
	) AS [Count]
FROM [Table1]

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

Taking a cue from the solution shared by hocine satour to a similar problem on  my Blog article here, this M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Text", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Count", each List.Count(List.ReplaceValue(Text.Split([Text], ","), " ", "", Replacer.ReplaceText)))
in
    #"Added Custom"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
az38
Community Champion
Community Champion

Hi @Qotsa 

create a calculated column

Column = 
PATHLENGTH(
SUBSTITUTE([Text Column];",";"|")
)

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.