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
borstroem
Regular Visitor

Count columns which contain text

Hi

 

I'm looking to create a new column which counts the columns which contains any text in that given row. Example:

 

IDXYZCells with text
1AppleOrangeBanana3
2BananaApple 2
3 Banana 1
4   0
5  Apple1
6OrangeApple 2

 

I guess I'm looking for a M equivalent of the excel function countif(row, "*")

 

Thanks a lot in advance 🙂

 

 

1 ACCEPTED SOLUTION
serpiva64
Super User
Super User

Hi,

you can obtain this

serpiva64_0-1675352411415.png

by applying the steps of the attached file

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

View solution in original post

2 REPLIES 2
latimeria
Solution Specialist
Solution Specialist

Hi @borstroem ,

 

Another way, using list

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIsKMhJBdL+RYl56SCGU2IeECrF6kQrGSG4CIVgGWMQA0kSLGgCEYRxTeFciFaQmBmyTQgTYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, X = _t, Y = _t, Z = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"Z"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Custom", each List.Count(List.Select(List.Skip(Record.ToList(_),1), each _ <> "" and _ <> null )))
in
    #"Added Custom"
serpiva64
Super User
Super User

Hi,

you can obtain this

serpiva64_0-1675352411415.png

by applying the steps of the attached file

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

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
Top Kudoed Authors