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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Count cells starting with text or containing text

Hello

 

How can I count cells in the matching below?

 

X*

*Y*Z*

 

i.e. cells that start with X and cells that contain both Y and Z in that order (first Y then Z).

 

The * is zero or any character

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column with using SEARCH function to to achieve it:

Count = 
var _searchX= SEARCH("X",'Text'[Name],1,0)
var _searchY= SEARCH("Y",'Text'[Name],1,0)
var _searchZ= SEARCH("Z",'Text'[Name],1,0)
RETURN IF(_searchX=1||(_searchY>1&&_searchZ>1&&_searchY<_searchZ),1,0)

count.JPG

 

Best Regards

Rena

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

You can create a calculated column with using SEARCH function to to achieve it:

Count = 
var _searchX= SEARCH("X",'Text'[Name],1,0)
var _searchY= SEARCH("Y",'Text'[Name],1,0)
var _searchZ= SEARCH("Z",'Text'[Name],1,0)
RETURN IF(_searchX=1||(_searchY>1&&_searchZ>1&&_searchY<_searchZ),1,0)

count.JPG

 

Best Regards

Rena

 

amitchandak
Super User
Super User

@Anonymous ,

 

Try a new column like

Column =
var _1 =SEARCH("Y",[Column],1,0)
var _2 =SEARCH("Z",[Column],1,0)

return
if(left([Column],1) = "X" && _1 >0 and _2 >_1,1,0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
DouweMeer
Impactful Individual
Impactful Individual

Something with find expression and switch perhaps? Where you put some logic on whether you find an x and whether the found location comes earlier than the found location of y. And if y is not found, than there is only x. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors