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

String Matching using Filter in Direct Query

Hello,

I have two tables in SQL DB

The first Table contains Column "Type" with the following values "Amazon, Store, Online Retail"

Type
Amazon
Store
Online Retail

 

The 2nd Table contains two columns CustomerID and TypeSelected

CustoemrIDTypeSelected
1some text ,Amazon , Sometext 
2some text ,OnlineRetail, Sometext 
3some text ,Store, Sometext 
4some text ,Amazon ABC , Sometext 

 

How can I create a filter/slicer using the First Table field 'Type' which applies on my 2nd table and only shows specific Type Rows

Example: Amazon is selected from Filter Only first and the Last row will return.

 

I am using SQL DB with Direct Query Connection

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@musmanrafiq , Create a measure like this and use it with columns of table 2

 

countrows(filter(Table2, search(selectedvalue(Table1[Type]), Table2[TypeSelected],,0) >0), [CustomerID])

View solution in original post

v-shex-msft
Community Support
Community Support

HI @musmanrafiq,

You can use the following measure formula as a filter on your visual to filter records based on type selections:

Measure = 
VAR currRow =
    SELECTEDVALUE ( T2[TypeSelected] )
VAR result =
    COUNTROWS (
        FILTER ( ALLSELECTED ( T1[Type] ), SEARCH ( [Type], currRow, 1, -1 ) > 0 )
    )
RETURN
    IF ( result > 0, 1, 0 )

Applying a measure filter in Power BI - SQLBI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

HI @musmanrafiq,

You can use the following measure formula as a filter on your visual to filter records based on type selections:

Measure = 
VAR currRow =
    SELECTEDVALUE ( T2[TypeSelected] )
VAR result =
    COUNTROWS (
        FILTER ( ALLSELECTED ( T1[Type] ), SEARCH ( [Type], currRow, 1, -1 ) > 0 )
    )
RETURN
    IF ( result > 0, 1, 0 )

Applying a measure filter in Power BI - SQLBI

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@musmanrafiq , Create a measure like this and use it with columns of table 2

 

countrows(filter(Table2, search(selectedvalue(Table1[Type]), Table2[TypeSelected],,0) >0), [CustomerID])

Thanks for the reply,

it says unexpected Parameter CustomerID

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.