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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

Use dax variable inside filter

I am trying to filter a table based on how another table is already filtered by building a variable and using it in the filter, but I seem to be doing something wrong. Here is a sample of the data I am working with:




I have built a filtered version of the table using the following code:


Filtered_ALL_METRICS_patient_pivot = 
    VAR _ConditionsList = 
        IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[CAD])), [CAD], " ") = "1", ", 'CAD'", "" )
        & IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[CHF])), [CHF], " ") = "1", ", 'CHF'", "" )
        & IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[COPDAsthma])), [COPDAsthma], " ") = "1", ", 'COPDAsthma'", "" )
        & IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[Diabete])), [Diabete], " ") = "1", ", 'Diabete'", "" )
        & IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[HLD])), [HLD], " ") = "1", ", 'HLD'", "" )
        & IF ( CONCATENATEX(DISTINCT(VALUES(AllPatients[HTN])), [HTN], " ") = "1", ", 'HTN'", "" )
    VAR _FilterList =  IF ( LEN ( _ConditionsList ) = 0, "'CAD', 'CHF', 'COPDAsthma', 'Diabete', 'HLD', 'HTN'", RIGHT ( _ConditionsList, LEN ( _ConditionsList ) - 2 ) )
    FILTER(ALL_METRICS_patient_pivot, ALL_METRICS_patient_pivot[metric] IN {_FilterList})


But no matter what I have selected, the filtered table is empty. What am I doing wrong?


I currently do not have relationships set up between the filtered table and any other table. I have tried connecting it to several other tables that are being filtered correctly, but this did not give me any rows in the filtered table.


I have confirmed that _FilterList is outputting what I intend (e.g., 'CAD', 'CHF', 'COPDAsthma', 'Diabete', 'HLD', 'HTN' if everything or nothing is selected, and 'CHF', 'Diabete' if just those two conditions are selected) by creating a metric that is the same but returns _FilterList instead. I included an x in front of the variable names in the metric to avoid any potential scoping issues.


Any help is appreciated, as dax is not my strong point!

Super User
Super User

You need to let the data model do that filtering work for you, or worst case use TREATAS to project the filter in one table onto another table.

Helpful resources

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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


Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.