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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
gooranga1
Power Participant
Power Participant

DAX multiple text search from SSRS report

I am writing an SSRS report based on DAX. I am not sure if this is possible or not.

I have several parameters for the report that are passed as id's using the below pattern which work fine.

 

 VAR __CompanyPS =
        SUBSTITUTE ( @CompanyDDS, ",", "|" )

 

then in the summarizecolumns filter

 

    FILTER (
        ALL ( Company[Company Id] ),
        PATHCONTAINS ( _CompanyPS, Company[Company Id] )
    )

 

I also want a parameter in the report that allows people to enter sku names or better still parts of sku names to filter as well.

There may be a SKUs called ABC123, ABC456, DEF123. The person could enter "ABC" and that would filter skus with ABC.

I can use ContainRows but that is only on exact matches no string searches as below.

 

DEFINE

   VAR _SkuPS =
        SUBSTITUTE ( "ABC123,ABC456", ",", "|" )

   VAR _SkuTable =
        SELECTCOLUMNS (
            GENERATESERIES ( 1, _len ),
            "Skus", PATHITEM ( _skuPS, [value], TEXT )
        )

EVALUATE
FILTER (
    ALL ( Products[sku], Products[Product Id] ),
    CONTAINSROW ( _skutable, Products[SKU] )
)

 

 it would be really nice to be able to allow multiple string searches as well as actual skus but I can't see how I could do this.

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @gooranga1,

 

Can you please try this approach to filter with multiple substrings:

DEFINE
    VAR __CompanyPS = SUBSTITUTE(@CompanyDDS, ",", "|")
    VAR __SkuParam = SUBSTITUTE(@SkuDDS, ",", "|")
    VAR __SkuPatterns = 
        ADDCOLUMNS(
            GENERATESERIES(1, PATHLENGTH(__SkuParam)), 
            "Pattern", PATHITEM(__SkuParam, [Value], TEXT)
        )

    VAR __MatchingSkus = 
        FILTER(
            ALL(Products[SKU]),
            SUMX(
                __SkuPatterns,
                IF(CONTAINSSTRING(Products[SKU], [Pattern]), 1, 0)
            ) > 0
        )

    VAR __FilteredTable =
        CALCULATETABLE(
            SUMMARIZECOLUMNS(
                Company[Company Id],
                Products[SKU],
                Products[Product Id],
                FILTER(
                    ALL(Company[Company Id]),
                    PATHCONTAINS(__CompanyPS, Company[Company Id])
                )
            ),
            __MatchingSkus
        )

EVALUATE __FilteredTable

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
gooranga1
Power Participant
Power Participant

thanks @Sahir_Maharaj that has worked!

DAX doesn't seem to be as flexible as SQL in filtering these. It would be optimal to have functionality like;

SELECT sku 
FROM Products as P
where p.sku like 'ABC%'

filtering skus that start with 'ABC' only rather than ABC occuring anywhere in the text string. The wildcard characters in DAX don't seem to work in the same way as SQL.

 

but this solution is definitely good enough for my purposes now.

Sahir_Maharaj
Super User
Super User

Hello @gooranga1,

 

Can you please try this approach to filter with multiple substrings:

DEFINE
    VAR __CompanyPS = SUBSTITUTE(@CompanyDDS, ",", "|")
    VAR __SkuParam = SUBSTITUTE(@SkuDDS, ",", "|")
    VAR __SkuPatterns = 
        ADDCOLUMNS(
            GENERATESERIES(1, PATHLENGTH(__SkuParam)), 
            "Pattern", PATHITEM(__SkuParam, [Value], TEXT)
        )

    VAR __MatchingSkus = 
        FILTER(
            ALL(Products[SKU]),
            SUMX(
                __SkuPatterns,
                IF(CONTAINSSTRING(Products[SKU], [Pattern]), 1, 0)
            ) > 0
        )

    VAR __FilteredTable =
        CALCULATETABLE(
            SUMMARIZECOLUMNS(
                Company[Company Id],
                Products[SKU],
                Products[Product Id],
                FILTER(
                    ALL(Company[Company Id]),
                    PATHCONTAINS(__CompanyPS, Company[Company Id])
                )
            ),
            __MatchingSkus
        )

EVALUATE __FilteredTable

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.