Forum Discussion

asparagus1_'s avatar
asparagus1_
Helper I
1 year ago
Solved

How to dynamically filter rows using a parameter table?

Hi everyone, I'm working on a Power BI report where users can select one or more KPIs from a parameter table (e.g., KPI1, KPI2, KPI3). I want to filter out rows from my data table where all selected...
  • v-achippa's avatar
    v-achippa
    1 year ago

    Hi asparagus1_,

     

    Thank you for reaching out to Microsoft Fabric Community.

     

    Thank you bhanu_gautam and wardy912 for the prompt response.

     

    Based on the requirement, you can still use the unpivot approach even if you only have a parameter table and no separate KPI table in your model.

    In Power Query, unpivot your KPI columns so the table has the format (Dimension, KPI, Value) using the KPI names from your parameter table so that it is fully dynamic. And when you add new KPIs to the parameter table, they are automatically included without changing the DAX.

     

    After unpivoting, create a measure for example like below:

    ShowRow = VAR SelectedKPIs = VALUES( Parameter[KPI] )

    VAR NonZeroCount =

        CALCULATE(

            COUNTROWS(YourUnpivotedTable),

            TREATAS(SelectedKPIs, YourUnpivotedTable[KPI]),

            YourUnpivotedTable[Value] <> 0

        )

    RETURN IF(NonZeroCount > 0, 1, 0)

     

    This measure will return 1 for any row where at least one of the selected KPIs in the parameter table has a non-zero value.

    And use ShowRow = 1 as a visual level filter. This works for any KPI selection and scales to any number of KPIs without listing combinations in DAX.

     

     

    Thanks and regards,

    Anjan Kumar Chippa