Forum Discussion

PrasadSwamy007's avatar
PrasadSwamy007
Regular Visitor
3 months ago
Solved

Power BI Dynamic Filter/Slicer

Hi, I have a data with columns Project ID, Source and Sub-Source & Sales

Project IDSourceSub-SourceSales
1ABCpack10
2ABC 20
3ABCpack30
4XYZ 40
5XYZ 50
6XYZ 60
7DEF 70
8DEF 80
9DEF 90

I want a slicer or filter such that it must have distinct values from source column but when XYZ is selected it must also include projects with sub-source "pack" and for rest the filter must be as usual. Example So when XYZ is selected the sum must be 190. When ABC is selected it must give 60. and DEFis selected it must give 240.

  • Hey PrasadSwamy007,

    1) Create a disconnected slicer table

    // DAX
    SlicerTable = DISTINCT('Table'[Source])

    2) Create this measure

    Custom Sales =
    VAR SelectedSource = SELECTEDVALUE('SlicerTable'[Source])
    RETURN
        CALCULATE(
            SUM('Table'[Sales]),
            FILTER(
                'Table',
                'Table'[Source] = SelectedSource
                    || (SelectedSource = "XYZ" && 'Table'[Sub-Source] = "pack")
            )
        )

    Key Results:

    • For ABC / DEF - filters normally by Source
    • For XYZ - also pulls in rows where Sub-Source = "pack"
    • Disconnected table ensures the slicer doesn't auto-filter your fact table

    Hope this helps!

    Best,

    Harshit

  • Hi,

     

    As per our understanding your requirement, you need a custom slicer behavior where:

    • Normally → filter by Source
    • But when XYZ is selected → also include rows where Sub-Source = "pack" (even if Source ≠ XYZ)

    So expected results:

    • ABC → 10 + 20 + 30 = 60
    • XYZ → 40 + 50 + 60 + pack(10 + 30) = 190
    • DEF → 70 + 80 + 90 = 240

    Recommended Solution (Measure-Based)

    Create a disconnected slicer table:

    Slicer_Source =
    DISTINCT(TableName[Source])

    Use this table in your slicer.

    Then create a measure:

    Sales Dynamic =
    VAR SelectedSource =
        SELECTEDVALUE(Slicer_Source[Source])

    RETURN
    CALCULATE(
        SUM(TableName[Sales]),
        FILTER(
            ALL(TableName),
            TableName[Source] = SelectedSource
            ||
            (
                SelectedSource = "XYZ"
                && TableName[Sub-Source] = "pack"
            )
        )
    )

    How it works

    For normal selections (ABC, DEF):

    Source = SelectedSource

    works normally.

    For XYZ:

    It additionally includes:

    Sub-Source = "pack"

    So:

    XYZ = 40 + 50 + 60 + 10 + 30 = 190

    Setup Steps

    1. Create Disconnected Slicer Table
    2. Add it to slicer
    3. Create the Sales Dynamic measure
    4. Use measure in cards/charts/tables

    Note:
    Do not use your original Source column directly in slicer, otherwise Power BI’s normal filtering will interfere.

    Use the disconnected slicer table only.

     

    This approach gives you fully dynamic custom filter logic

     

    Hope this helps.

     

    Thanks!

     

13 Replies

  • PrasadSwamy007 

     

    Handle this in a measure:

    Filtered Sales =
    VAR SelectedSource = SELECTEDVALUE('SlicerTable'[Source])
    RETURN
    CALCULATE(
    SUM('Table'[Sales]),
    FILTER(
    'Table',
    'Table'[Source] = SelectedSource
    || (SelectedSource = "XYZ" && 'Table'[Sub-Source] = "pack")
    )
    )

    Use a disconnected slicer table with distinct Source values. Do not connect it to your fact table via a relationship.

     

    • PrasadSwamy007's avatar
      PrasadSwamy007
      Regular Visitor
      Thank you kedar
      Sorry I forgot to mention the matrix has this measure : Display_final =
      if(ISINSCOPE('Diagonal Lookup2027'[Year]),[Display_2026],[total_2025_2026])
      The sales column was an example, The above measure has been used in matrrix Values and that has to be filtered. Also the measure that you have provided has to be used in Slicer or the matrix visual (set it = 1)?
  • Hey PrasadSwamy007,

    1) Create a disconnected slicer table

    // DAX
    SlicerTable = DISTINCT('Table'[Source])

    2) Create this measure

    Custom Sales =
    VAR SelectedSource = SELECTEDVALUE('SlicerTable'[Source])
    RETURN
        CALCULATE(
            SUM('Table'[Sales]),
            FILTER(
                'Table',
                'Table'[Source] = SelectedSource
                    || (SelectedSource = "XYZ" && 'Table'[Sub-Source] = "pack")
            )
        )

    Key Results:

    • For ABC / DEF - filters normally by Source
    • For XYZ - also pulls in rows where Sub-Source = "pack"
    • Disconnected table ensures the slicer doesn't auto-filter your fact table

    Hope this helps!

    Best,

    Harshit

  • Hi,

     

    As per our understanding your requirement, you need a custom slicer behavior where:

    • Normally → filter by Source
    • But when XYZ is selected → also include rows where Sub-Source = "pack" (even if Source ≠ XYZ)

    So expected results:

    • ABC → 10 + 20 + 30 = 60
    • XYZ → 40 + 50 + 60 + pack(10 + 30) = 190
    • DEF → 70 + 80 + 90 = 240

    Recommended Solution (Measure-Based)

    Create a disconnected slicer table:

    Slicer_Source =
    DISTINCT(TableName[Source])

    Use this table in your slicer.

    Then create a measure:

    Sales Dynamic =
    VAR SelectedSource =
        SELECTEDVALUE(Slicer_Source[Source])

    RETURN
    CALCULATE(
        SUM(TableName[Sales]),
        FILTER(
            ALL(TableName),
            TableName[Source] = SelectedSource
            ||
            (
                SelectedSource = "XYZ"
                && TableName[Sub-Source] = "pack"
            )
        )
    )

    How it works

    For normal selections (ABC, DEF):

    Source = SelectedSource

    works normally.

    For XYZ:

    It additionally includes:

    Sub-Source = "pack"

    So:

    XYZ = 40 + 50 + 60 + 10 + 30 = 190

    Setup Steps

    1. Create Disconnected Slicer Table
    2. Add it to slicer
    3. Create the Sales Dynamic measure
    4. Use measure in cards/charts/tables

    Note:
    Do not use your original Source column directly in slicer, otherwise Power BI’s normal filtering will interfere.

    Use the disconnected slicer table only.

     

    This approach gives you fully dynamic custom filter logic

     

    Hope this helps.

     

    Thanks!

     

  • Create a disconnected table with all sources for use in the slicer. You can do this in DAX with

    Source for Slicer = DISTINCT( 'Table'[Source] )

    or you could do it in Power Query.

    Do not connect this new table to your main table.

    Create a measure like

    Sales Measure = 
    VAR CurrentSource = SELECTEDVALUE( 'Source for Slicer'[Source] )
    VAR PackSales = CALCULATE(
        SUM( 'Table'[Sales] ),
        'Table'[Sub-Source] = "pack"
    )
    VAR SelectedSales = CALCULATE(
        SUM( 'Table'[Sales] ),
        TREATAS( { CurrentSource }, 'Table'[Source] )
    )
    VAR Result = IF( CurrentSource = "XYZ",
        SelectedSales + PackSales,
        SelectedSales
    )
    RETURN Result
  • Hello,

    I’m not completely sure, but I think the easiest way is to keep the slicer on Source and handle the special XYZ logic inside a measure with SWITCH or IF.

    Something like, if selected source = "XYZ" then calculate Sales where Source = "XYZ" OR Sub-Source = "pack", otherwise just filter normally by Source. That should give you 190 for XYZ, 60 for ABC and 240 for DEF.

    Best regards,
    Daniele

      • v-priyankata's avatar
        v-priyankata
        Community Support

        Hi PrasadSwamy007 

        Thank you for reaching out to the Microsoft Fabric Forum Community.

        DanieleUgoCopp trivedisunita stoic-harsh SamInogic Thank you so much for your inputs.
        I hope the suggestions from users have been helpful. Please confirm whether your issue has been resolved. If not, try the following steps.

        Since your matrix is already using Display_final, the SUM(Sales) measure was just an example to illustrate the filtering logic.

        In your case, you wouldn't use the measure in the slicer or as a visual-level filter (=1). Instead, the same XYZ/pack logic would need to be applied to a new measure that references Display_final, and that measure should be used in the matrix Values.

        If you're able to share the definitions of Display_2026 and total_2025_2026 it would help confirm the exact DAX needed, as the filtering behavior can depend on how those measures are written.

         

        If there are any deviations from your expectation please let us know we are happy to address.

        Thanks.

  • trivedisunita's avatar
    trivedisunita
    Continued Contributor

    Hi PrasadSwamy007 ,

    You can create a separate slicer calculated table to capture the user selection without directly filtering the main table.
    The default slicer behavior only filters matching Source values and cannot dynamically include rows from another category when XYZ is selected.

    Use this calculated table in the slicer and keep it disconnected from the main table.

    SlicerSource =DISTINCT(test[Source]).

     

    Step-2

    This custom DAX measure is created to manually handle the filtering logic based on what the user selects in the slicer. Normally, the measure behaves like a regular filter and returns sales only for the selected source. However, the business requirement for XYZ is different — when users select XYZ, they also want to include all projects where Sub-Source = "pack" even if those rows belong to another source category like ABC.

    To achieve this, the measure dynamically changes the filter context. It checks the selected slicer value and applies conditional logic.

    For normal selections like ABC or DEF, it filters data normally
    but for XYZ, it expands the filter condition to include both XYZ rows and pack rows.

     

     

    you can create measure like this-

    Custom Sales =

    VAR SelectedSource =
       SELECTEDVALUE(SliderSource[Source])

    RETURN
    CALCULATE(
        SUM(test[Sales]),
        FILTER(
            test,
            (
                SelectedSource <> "XYZ"
                && test[Source] = SelectedSource
            )
            ||
            (
                SelectedSource = "XYZ"
                &&
                (
                    test[Source] = "XYZ"
                    || test[Sub-Source] = "pack"
                )
            )
        )
    )
     

     

     

     

     

     

    I hope this helps.

    Let me know if you face any issues while implementing it.

     

     

     

     

    • PrasadSwamy007's avatar
      PrasadSwamy007
      Regular Visitor
      Sorry I forgot to mention the matrix has this measure : Display_final = if(ISINSCOPE('Diagonal Lookup2027'[Year]),[Display_2026],[total_2025_2026])
      The sales column was an example, The above measure has been used in matrrix Values and that has to be filtered. Also the measure that you have provided has to be used in Slicer or the matrix visual (set it = 1)?
  • ryan654321's avatar
    ryan654321
    Frequent Visitor

    Hi  PrasadSwamy007 

    Could you please confirm if the issue has been resolved? If not, feel free to reach out if you have any further questions.

    Your update would be helpful for other members who may face a similar issue.