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
Anonymous
Not applicable

How do I count a string under "contains" function - Custom column

Hello,

 

New to PowerBI, had some issues with custom column.

 

I'm trying to count rows which contains certain words (12 month / 1 year) and a certain condition from 2 seperate columns.

The Duration column contains many different string but with a similarity at the beggining with Capslock and without (12 months/ 12 Months or 1 year/ 1 Year).

Here is the code im using, no syntax errors, but also no results 😞

 

if [Event]="Transformation" and ([Duration] like "12 Month%" or [Duration] like "1 Year%") then 1 else null

 

This code isnt working since it only returns nulls.

I know where the issue is - like function as in sql and im trying to find it Powerbi's function.

 

Thanks!

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , In power query

if [Event]="Transformation" and (Text.Contains([Duration] ,"12 Month%") or Text.Contains([Duration], "1 Year%")) then 1 else null

 

DAX

 

if ( [Event]="Transformation" && (CONTAINSSTRING([Duration] ,"12 Month%") || CONTAINSSTRING([Duration], "1 Year%")) , 1 , blank())

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , In power query

if [Event]="Transformation" and (Text.Contains([Duration] ,"12 Month%") or Text.Contains([Duration], "1 Year%")) then 1 else null

 

DAX

 

if ( [Event]="Transformation" && (CONTAINSSTRING([Duration] ,"12 Month%") || CONTAINSSTRING([Duration], "1 Year%")) , 1 , blank())

Anonymous
Not applicable

Its working perfectly!

Thanks a lot!

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.