Forum Discussion

leonaxhero's avatar
leonaxhero
New Member
1 year ago
Solved

Dynamic Data Tagging based on Slicer Selection

Hi everyone! šŸ‘‹ I’m working on a Power BI report and need help creating a matrix visualization using a table with the following fields: Posting Period (formatted as YYYYMM) Entity Jurisdiction ...
  • Raju_17_97's avatar
    1 year ago

    Hi leonaxhero ,


    Here's how you can achieve dynamic data tagging based on slicer selection:

    Solution Overview: Create 3 disconnected tables and use a dynamic measure to control what data shows based on user selections.

    Step 1: Create Disconnected Tables

     

    dax
    // Table 1 - For start date selection
    OP_Sel = DISTINCT(
    SELECTCOLUMNS(
    'SampleData',
    "Posting Period", 'SampleData'[Posting Period]
    )
    )

    // Table 2 - For end date selection
    CP_Sel = DISTINCT(
    SELECTCOLUMNS(
    'SampleData',
    "Posting Period", 'SampleData'[Posting Period]
    )
    )

    // Table 3 - Category tags
    TagTable = DATATABLE(
    "Type Tag", STRING,
    {
    {"Opening Balance"},
    {"Current Year Activity"}
    }
    )
    Step 2: Create Dynamic Measure

     

    dax
    Dynamic Value = VAR SelectedTag = SELECTEDVALUE(TagTable[Type Tag])
    VAR StartDate = MIN('OP_Sel'[Posting Period])
    VAR EndDate = MAX('CP_Sel'[Posting Period])
    VAR CurrentRowDate = MAX('SampleData'[Posting Period])

    RETURN
    SWITCH(
    TRUE(),
    SelectedTag = "Opening Balance" && CurrentRowDate < StartDate,
    SUM('SampleData'[Value]),
    SelectedTag = "Current Year Activity" && CurrentRowDate >= StartDate && CurrentRowDate <= EndDate,
    SUM('SampleData'[Value]),
    BLANK()
    )
    How it works:

    Users select date ranges with OP_Sel and CP_Sel slicers
    TagTable values switches between "Opening Balance" (shows data before start date) and "Current Year Activity" (shows data within selected range)
    The measure dynamically filters data based on these selections

    Thanks