Writing a DAX function to filter out multiple criteria for a given product

@tomtom62,

Welcome to the forum! I think you’ll find this to be a terrific resource and a wonderful community.

If I understand your requirement correctly, this can be handled via a standard CALCULATE/FILTER construct using some text functions: LEFT() and CONTAINSSTRING() to generate your filter conditions. Here’s what the DAX measure would look like:

Filtered Total Sales = 
    CALCULATE(
        [Total Sales],
        FILTER(
            Products,
            LEFT( Products[Product Name], 1) = [Harvest Starts With] &&
            CONTAINSSTRING( Products[Product Name], [Harvest Does Not Contain] ) = FALSE 
        )
    ) 

As a newcomer to DAX, I would very strongly recommend that you go through the lessons below really thoroughly, focusing specifically on understanding evaluation, filter and row context. It takes everyone a while to truly understand these concepts (and Sam has a lot more great videos that go further in depth on these topics), but without that understanding it’s difficult to do anything useful in DAX.

I hope this is helpful to you. Full solution file posted below.

2 Likes