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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
steambucky
Helper III
Helper III

vairable value for a calculated column based specific words found in text data

I have some of the ideas, but not all to create the calculated column I need.

 

I want to write a calculated column where the value varies depending what specific words it finds in the text.

 

There are the words we are looking for:

 

Big = 1

Black = 1

Cats = 1

 

Data and the value I would be expecting

 

I like big black cats = 3

I like big black dogs = 2

I like big ginger cats = 2

I like Black animals = 1

I like dogs  =  0

I like cats =  1

 

I THINK that I need to write some scripting that, if written in just plain English would be like this:

 

Big_black_cats = IF(

        (If Data contains  = big then Big_black_cats = Big_black_cats +1)

        (If Data contains  = black then Big_black_cats = Big_black_cats +1)

        (If Data contains  = cat then Big_black_cats = Big_black_cats +1)

                                )             

 

I know that’s NOT right,  but can anyone get me started?

1 ACCEPTED SOLUTION
affan
Solution Sage
Solution Sage

@steambucky

 

You can use the following to create a calculated column

 

CalcCats = var _black=IF (
ISBLANK ( SEARCH ( "Black", Table1[Data], 1, BLANK () ) ),
0,1)
var _big=IF (
ISBLANK ( SEARCH ( "big", Table1[Data], 1, BLANK () ) ),
0,1)
var _cats=IF (
ISBLANK ( SEARCH ( "cats", Table1[Data], 1, BLANK () ) ),
0,1)
return _black+_big+_cats

text search.png

 

Attached is the file

 

If this helped you, please mark this post as an accepted solution and like to give KUDOS .

 

Regards,

Affan

View solution in original post

3 REPLIES 3
affan
Solution Sage
Solution Sage

@steambucky

 

You can use the following to create a calculated column

 

CalcCats = var _black=IF (
ISBLANK ( SEARCH ( "Black", Table1[Data], 1, BLANK () ) ),
0,1)
var _big=IF (
ISBLANK ( SEARCH ( "big", Table1[Data], 1, BLANK () ) ),
0,1)
var _cats=IF (
ISBLANK ( SEARCH ( "cats", Table1[Data], 1, BLANK () ) ),
0,1)
return _black+_big+_cats

text search.png

 

Attached is the file

 

If this helped you, please mark this post as an accepted solution and like to give KUDOS .

 

Regards,

Affan

Thanks so much for your help. 

Zubair_Muhammad
Community Champion
Community Champion

@steambucky

 

You can use this calculated column

See attached file as well

 

Calculated Column =
SUMX (
    ADDCOLUMNS (
        Words,
        "Number of Matches", IF ( SEARCH ( [Words], [Sentence], 1, 0 ) > 0, 1 )
    ),
    [Number of Matches]
)

 

var value.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.