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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Portrek
Resolver III
Resolver III

Calculate with filters and Contaimstring with OR

Hello everyone, i need help for elaborate a med.

 

I need  to calculate the amount the records in the collunm by type text that contaim the diferents words.

 

For Example, I need a formula that brings me the added value if the column contains the text XXXX or YYYY or ZZZZZ

 

I thing that has beem something with CALCULATE / FILTER / CONTAINSTRING (or other text function) with the funcition OR

 

How i can do that ?

 

Thanks a lot for the answers.

 

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Portrek 

 

Based on your description, I assume that you want to count rows which contains specific words and get the text which excludes the specific words. I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

You may create two measures as below.

CountRecords = 
COUNTROWS(
    FILTER(
        ALL('Table'),
        CONTAINSSTRINGEXACT('Table'[Text],"XXXX")||
        CONTAINSSTRINGEXACT('Table'[Text],"YYYY")||
        CONTAINSSTRINGEXACT('Table'[Text],"ZZZZ")
    )
)

Result = 
var _text = SELECTEDVALUE('Table'[Text])
return
SWITCH(
    TRUE(),
    CONTAINSSTRINGEXACT(_text,"XXXX"),
    SUBSTITUTE(_text,"XXXX",""),
    CONTAINSSTRINGEXACT(_text,"YYYY"),
    SUBSTITUTE(_text,"YYYY",""),
    CONTAINSSTRINGEXACT(_text,"ZZZZ"),
    SUBSTITUTE(_text,"ZZZZ","")
)

 

Result:

a2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @Portrek 

 

Based on your description, I assume that you want to count rows which contains specific words and get the text which excludes the specific words. I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

a1.png

 

You may create two measures as below.

CountRecords = 
COUNTROWS(
    FILTER(
        ALL('Table'),
        CONTAINSSTRINGEXACT('Table'[Text],"XXXX")||
        CONTAINSSTRINGEXACT('Table'[Text],"YYYY")||
        CONTAINSSTRINGEXACT('Table'[Text],"ZZZZ")
    )
)

Result = 
var _text = SELECTEDVALUE('Table'[Text])
return
SWITCH(
    TRUE(),
    CONTAINSSTRINGEXACT(_text,"XXXX"),
    SUBSTITUTE(_text,"XXXX",""),
    CONTAINSSTRINGEXACT(_text,"YYYY"),
    SUBSTITUTE(_text,"YYYY",""),
    CONTAINSSTRINGEXACT(_text,"ZZZZ"),
    SUBSTITUTE(_text,"ZZZZ","")
)

 

Result:

a2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

nvprasad
Solution Sage
Solution Sage

Hi,

 

Can you try the below function?

Count_string =
CALCULATE (
COUNTROWS ( 'Table' ),
CONTAINSSTRING ( Table[Column], "XXXX" )
|| CONTAINSSTRING ( Table[Column], "YYYY" )
)

Appreciate a Kudos! 🙂
If this helps and resolves the issue, please mark it as a Solution! 🙂

Regards,
N V Durga Prasad

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.