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
morgtd30
Helper I
Helper I

Multi-Select filtering column checking if it contains multiple pieces of text

I've tried using this solution, but it seems to work on an OR basis
https://community.powerbi.com/t5/Desktop/Dynamic-filtering-slicing-if-text-contains/td-p/425504

 

I'd like to achieve the following:

 

Data:

Date         Text
2018-11-01   Apples
2018-04-03   Apples; Oranges; Grapes
2018-02-01   Apples; Oranges
2018-01-03 Oranges; Grapes; Bananas

Slicer:

[  ] Apples
[ x ] Oranges
[ x ] Grapes
[  ] Bananas

Should filter to orders which included Oranges AND Grapes, but could have include other items as well:

Date         Text
2018-04-03 Apples; Oranges; Grapes
2018-01-03 Oranges; Grapes; Bananas

Thank you!

10 REPLIES 10
v-yetao1-msft
Community Support
Community Support

Hi @morgtd30 

(1)Create a table with selection “Apples”,” Oranges”,” Grapes”,” Bananas”.

Ailsamsft_0-1633079622468.png

(2)Add a slicer with [Slicer] .And then create a measure to return the string of select value .

Measure 2 = CALCULATE(CONCATENATEX(VALUES(Slicer[Slicer]),Slicer[Slicer],"; "))

Ailsamsft_1-1633079622471.png

(3)Create a measure to judge whether the Measure 2 in the column [Text] .If yes ,return 1 , otherwise return 0 .

CONTAINSSTRING = IF(CONTAINSSTRING(SELECTEDVALUE('Table'[Text]),Slicer[Measure 2]),1,0)

Ailsamsft_2-1633079622473.png

(4)Put the CONTAINSSTRING measure in visual filter and set CONTAINSSTRING is equal to 1 .The final result is as shown :

Ailsamsft_3-1633079622474.png

Ailsamsft_4-1633079622475.png

I have attached my pbix file , you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

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

Hi @v-yetao1-msft ,

 

Do you realize that your solution makes that if the order of the words are different then it does not return any result?

 

I have added a line with different values and the result is below:

MFelix_0-1633086475782.png

Has you can see in your solution you are missing one line.

 

This is happening because using the CONCANATEX you are forcing the order of the text using my solution since I'm looking at individual words it shows the result:

MFelix_1-1633086718172.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @morgtd30 ,

 

I made a similar approach to this on this post:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Find-Words-on-sentence-from-another-selected...

 

Making some small adjustment I was abble to reach the following measure:

Find Word Formula_V2 = 
// Character that split phrase into words
VAR SplitByCharacter = " " 

// Temporary table that splits selected phrase into words
VAR Words_table =
   
        ADDCOLUMNS (
            GENERATE (
                SELECTCOLUMNS (
                    ALLSELECTED (Slicer[Slicer] ),
                    "Find_Text", Slicer[Slicer]
                ),
                VAR TokenCount =
                    PATHLENGTH ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ) )
                RETURN
                    GENERATESERIES ( 1, TokenCount )
            ),
            "Word", PATHITEM ( SUBSTITUTE ( [Find_Text], SplitByCharacter, "|" ), [Value] )
        )
RETURN
    IF (
// Function that returns the sum of the values of the words found in the sentance
        SUMX (
            Words_table,
            FIND (
// additonal spaces in the beginning and ending of each word allows to find the exact match, also removed the last "." so that would be specific words
                 UPPER ( [Word] ) & " ",
                 UPPER (  SELECTEDVALUE ( 'Table'[Text] ) ) &" ",
                ,
                0
            )
        ) > 0,
        1,
        BLANK ()
    )

 

See result below and in attach PBIX file:

MFelix_0-1633078405524.png

 

If you want you can set the measure on the visualization filter pane and set it to non blank values.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi,

When only Apples is selected, you expect that the table give 3 rows as a result.no result is showing in the table. But in stead only the row with only apples shows up. 

JeBro_1-1697657232400.png

 

 

 

The expected result is 3 rows because we are looking for a word inside a frase not a full match


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi,

 

Thanks, but what i ment is my result is 1 instead of the expected 3 with your example.

Hi @JeBro 

 

Are you using the same example as mine or is your different? Are you using the sample file I provided?

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi, yes, i used the one provided by you

Hi @JeBro ,

 

Have you made any change to the measures or model? I just downloaded the file and all works correctly:

MFelix_0-1698050288844.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi MFelix! I stumbled across your post while looking for a measure to solve an issue I'm facing in PowerBI. 

From your last message, do you have a measure that when Apples and Oranges are selected from the slicer, only row 01/02/2018 appears, and when Apples, Oranges and Grapes are selected fromt he slicer, only row 03/04/2018 appears. 

But when only Apples are selected on the slicer, then all three rows will appear. 

Thanks in advance!

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.