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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sudden1sam
New Member

FInd ALL slicer selections within a string field

My primary fact table has a field (Products) that contains one or many products separated by semicolons. I have a second table with the unique product names, from which I've created a slicer. I would like to use the slicer to select records from the primary fact table where ALL of the selected slicer values appear in the Products field. In the example below, where Blue and Brown are selected in the slicer, I would like the primary table to filter to only Product 4341, the only row where BOTH Blue and Brown appear in Products. 

 

sudden1sam_0-1735225406218.png

 

I am aware that I could use Data Transformation to break the rows in the primary data table, but don't want to. I am ultimately trying to provide users with a filtered table with records that meet the selected criteria, and would like to count those records.

1 ACCEPTED SOLUTION
olgad
Super User
Super User

Ensure there’s no direct relationship between the Products column in the fact table and the slicer table. 

Try this:

FilteredRowCount =
VAR SelectedProducts = VALUES(SlicerTable[ProductName]) -- Get selected slicer values
VAR FactTableRows =
ADDCOLUMNS(
'FactTable',
"@MatchCount",
COUNTROWS(
FILTER(
SelectedProducts,
SEARCH(";" & [ProductName] & ";", ";" & FactTable[Products] & ";", 1, 0) > 0
)
)
)
VAR FilteredRows =
FILTER(
FactTableRows,
COUNTROWS(SelectedProducts) = [@MatchCount]
)
RETURN
COUNTROWS(FilteredRows)


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime

View solution in original post

3 REPLIES 3
sudden1sam
New Member

Thank you, Olgad. For others who might read this topic, I had to fuss a little with the arguments to SEARCH. Specifically, I eliminated the concatentations (all of the "&"s) so that my SEARCH looked more like the following:
 

SEARCH (
       ( [SlicerSelection] ) ,
       ( [FactTableField] ),
       1, ) > 0
 
 
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1735235946434.png

 

PATH function (DAX) - DAX | Microsoft Learn

 

PATHITEM function (DAX) - DAX | Microsoft Learn

 

selected order id list = 
VAR _n =
    COUNTROWS ( ALL ( products ) )
VAR _filtercount =
    COUNTROWS ( products )
VAR _series =
    GENERATESERIES ( 1, _n, 1 )
VAR _path =
    ADDCOLUMNS ( 'order', "@path", SUBSTITUTE ( 'order'[products], "; ", "|" ) )
VAR _pathiteminrows =
    GENERATE (
        _series,
        VAR _number = [Value]
        RETURN
            ADDCOLUMNS ( _path, "@pathitem", PATHITEM ( [@path], _number ) )
    )
VAR _t =
    FILTER (
        SUMMARIZE ( _pathiteminrows, 'order'[order_id], [@pathitem] ),
        [@pathitem] <> BLANK ()
    )
VAR _productlist =
    VALUES ( products[products] )
VAR _selectedorderidlist =
    FILTER (
        ADDCOLUMNS (
            _t,
            "@filtercount",
                COUNTROWS (
                    FILTER (
                        _t,
                        EARLIER ( [order_id] ) = 'order'[order_id]
                            && [@pathitem] IN _productlist
                    )
                )
        ),
        [@filtercount] = _filtercount
    )
RETURN
    IF (
        ISFILTERED ( products[products] ),
        CONCATENATEX (
            SUMMARIZE ( _selectedorderidlist, 'order'[order_id] ),
            'order'[order_id],
            ", "
        )
    )

 

 

count selected order id list = 
VAR _n =
    COUNTROWS ( ALL ( products ) )
VAR _filtercount =
    COUNTROWS ( products )
VAR _series =
    GENERATESERIES ( 1, _n, 1 )
VAR _path =
    ADDCOLUMNS ( 'order', "@path", SUBSTITUTE ( 'order'[products], "; ", "|" ) )
VAR _pathiteminrows =
    GENERATE (
        _series,
        VAR _number = [Value]
        RETURN
            ADDCOLUMNS ( _path, "@pathitem", PATHITEM ( [@path], _number ) )
    )
VAR _t =
    FILTER (
        SUMMARIZE ( _pathiteminrows, 'order'[order_id], [@pathitem] ),
        [@pathitem] <> BLANK ()
    )
VAR _productlist =
    VALUES ( products[products] )
VAR _selectedorderidlist =
    FILTER (
        ADDCOLUMNS (
            _t,
            "@filtercount",
                COUNTROWS (
                    FILTER (
                        _t,
                        EARLIER ( [order_id] ) = 'order'[order_id]
                            && [@pathitem] IN _productlist
                    )
                )
        ),
        [@filtercount] = _filtercount
    )
RETURN
    IF (
        ISFILTERED ( products[products] ),
        COUNTROWS ( SUMMARIZE ( _selectedorderidlist, 'order'[order_id] ) )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
olgad
Super User
Super User

Ensure there’s no direct relationship between the Products column in the fact table and the slicer table. 

Try this:

FilteredRowCount =
VAR SelectedProducts = VALUES(SlicerTable[ProductName]) -- Get selected slicer values
VAR FactTableRows =
ADDCOLUMNS(
'FactTable',
"@MatchCount",
COUNTROWS(
FILTER(
SelectedProducts,
SEARCH(";" & [ProductName] & ";", ";" & FactTable[Products] & ";", 1, 0) > 0
)
)
)
VAR FilteredRows =
FILTER(
FactTableRows,
COUNTROWS(SelectedProducts) = [@MatchCount]
)
RETURN
COUNTROWS(FilteredRows)


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.