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 ID Source Sub-Source Sales 1 ABC pack 10 2 ABC   20 3 ABC pack 30 4 XYZ   40 5 XYZ ...
  • stoic-harsh's avatar
    3 months ago

    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

  • SamInogic's avatar
    3 months ago

    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!