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
MarkHansen
Frequent Visitor

Counting how many times a word is in a column

I've looked at many similar suggested strings but since I'm new to Powr BI and DAX, I'm having a hard time translating the solutions into what I need.

 

I have a columns labled "Emotional Depression" and in that column will be "Depression" if the client checked a box saying they were having a hard time with depression.  So each row in that column will either be blank, or have the word "Depression".  (A little strange data set I know, but I used the data to assist with writing a note.)

 

Eventually I would like to make a pie chart with the numbers because I have four Emotional columns but I can't even get out of the gate with getting a usable number.

 

I assume I need to create a measure, but can't get the DAX correct (if that's even the correct way to go).

 

Thanks for any insight.

 

1 ACCEPTED SOLUTION
Dog
Responsive Resident
Responsive Resident

you could also (as just realised that the column would only contain this word or nothing) 

 

ContainsDepression=
IF([Emotional Depression] = "Depression",1, 0)

View solution in original post

5 REPLIES 5
sokatenaj
Helper III
Helper III

You can create a measure using this formula:

 

# Depression = CALCULATE(COUNTAX('TableName','TableName'[Emotional Depression]),'TableName'[Emotional Depression]="Depression")

 

Everytime you update your feed, it will update the count. 

 

Edit: Forgot the apostrophes. 

Thanks, I'll give that one a try too1

MarkHansen
Frequent Visitor

Thanks for you quick and accurate reply Dog.  I appreciage the help!!

 

Mark

Dog
Responsive Resident
Responsive Resident

Hi @MarkHansen

 

I suppose an easy way through DAX is to create a calculate column first off which checks if it can find the word depression in the column. I use "SEARCH" because it's not case sensitive. 

 

ContainsDepression=
var IsFound = SEARCH("Depression", [Emotional Depression], ,0)

RETURN
IF(IsFound = 0, 0, 1)

 

you can then create a new measure that simply counts up these values. 

DepressionRows:=Calculate(sum([ContainsDepression]))

 

not sure if this helps or not? 

 

Dog

 

 

Dog
Responsive Resident
Responsive Resident

you could also (as just realised that the column would only contain this word or nothing) 

 

ContainsDepression=
IF([Emotional Depression] = "Depression",1, 0)

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.