Forum Discussion

Amyries's avatar
Amyries
Helper I
10 months ago
Solved

Dropdown list in slicer

Hi everyone, I have a table called V_ABC, as shown in the photo below. I am wondering if Power BI can create dropdown lists called "From Week" and "To Week," allowing users to select values correspo...
  • Khashayar's avatar
    10 months ago

    Yes, absolutely possible in Power BI. Below I give a clear, working approach (step-by-step) plus the exact DAX you can drop into your model. The idea: make a small Week table (with a numeric week column), use two single-select slicers from that table as From Week and To Week, and then create measures that (1) apply the chosen range and (2) validate that To > From. Project_ID and Phase_ID slicers will naturally limit the weeks shown if you build the relationship as described.

     

    1) Create a Week table (calculated table)

    Use this calculated table in Modeling → New table:

    WeekTable =

    VAR w =

        ADDCOLUMNS(

            DISTINCT ( V_ABC[Phase_Week] ),

            "WeekNum",

                VALUE (

                    SUBSTITUTE( TRIM( [Phase_Week] ), "Week ", "" )

                )

        )

    RETURN

    SELECTCOLUMNS( w, "Phase_Week", [Phase_Week], "WeekNum", [WeekNum] )

     

    Notes:

    • This extracts WeekNum from strings like "Week 1". Adjust the SUBSTITUTE if your labels differ.
    • WeekTable[Phase_Week] will be used for the slicer labels, and WeekNum is numeric for comparisons.

     

    2) Create a relationship

    Make a relationship in the model:

    • WeekTable[WeekNum] (one) → V_ABC[WeekNum] (many).

    If V_ABC does not yet have a numeric WeekNum, add a calculated column there:

    V_ABC_WeekNum =

    VALUE( SUBSTITUTE( TRIM( V_ABC[Phase_Week] ), "Week ", "" ) )

     

    Then relate WeekTable[WeekNum] → V_ABC[V_ABC_WeekNum].

    This relationship enables the Project_ID and Phase_ID slicers (on fields from V_ABC) to cross-filter the WeekTable, displaying only weeks relevant to the selected project/phase.

     

    3) Add slicers to the report

    • Add slicer for V_ABC[Project_ID] (multi or single select as you want).
    • Add slicer for V_ABC[Phase_ID].
    • Add two slicers for the week using WeekTable[Phase_Week]:
      • Label one slicer "From Week"
      • Label the other "To Week"
      • Set both week slicers to Single select (so the user picks one value each).

    Because of the relationship, when you select a Project and Phase, the week slicers will show only weeks available for that project/phase.

     

    4) Selected week measures

    Create these helper measures:

    SelectedFromWeekNum :=

    SELECTEDVALUE( WeekTable[WeekNum] )

     

    SelectedToWeekNum :=

    SELECTEDVALUE( WeekTable[WeekNum] )

     

    (You can place them in a card during testing to see values; they return blank if nothing is selected.)

     

    5) Validation measure (To must be > From)

    Create a validation measure to show whether the selection is valid:

    IsWeekRangeValid :=

    VAR f = [SelectedFromWeekNum]

    VAR t = [SelectedToWeekNum]

    RETURN

    IF(

        OR( ISBLANK(f), ISBLANK(t) ),

        BLANK(),            // no message until both selected

        IF( t > f, 1, 0 )

    )

     

    You can show this as a Card or use it in conditional formatting. 1 = valid, 0 = invalid.

    Or an explanatory text measure for users:

    WeekRangeMessage :=

    VAR f = [SelectedFromWeekNum]

    VAR t = [SelectedToWeekNum]

    RETURN

    IF(

        OR( ISBLANK(f), ISBLANK(t) ),

        "Please select From and To weeks.",

        IF( t <= f, "Error: To Week must be greater than From Week.", "" )

    )

     

    Put WeekRangeMessage in a Card so users get immediate feedback.

     

    6) Main measure that restricts data to the selected range

    Example: count rows (or compute other metrics) in the selected week range and respecting Project_ID & Phase_ID slicers:

    RowsInSelectedWeekRange :=

    VAR f = [SelectedFromWeekNum]

    VAR t = [SelectedToWeekNum]

    RETURN

    IF(

        OR( ISBLANK(f), ISBLANK(t) ),

        BLANK(),                        // or 0 if you prefer

        IF(

            t <= f,

            BLANK(),                    // invalid selection -> blank (won't plot)

            CALCULATE(

                COUNTROWS( V_ABC ),

                FILTER(

                    V_ABC,

                    V_ABC[V_ABC_WeekNum] >= f

                    && V_ABC[V_ABC_WeekNum] <= t

                )

            )

        )

    )

     

    Important: I did not remove filters in CALCULATE, so this result will still honor Project_ID and Phase_ID slicers. If you do want to ignore Project/Phase filters, wrap the V_ABC table with ALL(V_ABC) inside FILTER.

     

    7) UX tips/enforcement

    • Power BI slicers themselves cannot force “To > From” (you can’t block a bad selection directly inside the slicer). Instead:
      • Use the WeekRangeMessage card to show an error message when the user picks an invalid range.
      • Use your measures to return BLANK() (or 0) when selection is invalid so charts/tables show nothing (or an alternate visualization prompting correction).
    • Make both week slicers single select — this simplifies the logic.
    • Optionally add a bookmark or a button wired to a measure/bookmark to clear selections (if you want a “Reset weeks” control).
    • If your Phase_Week values are not always formatted as "Week N", adapt the parsing logic accordingly.

     

    Example flow for the user

    1. User filters Project_ID and Phase_ID (optional).
    2. The From & To Week slicers show only weeks that exist for that project/phase.
    3. User picks From and To (single values). If To ≤ From:
    • WeekRangeMessage card warns: “To Week must be greater than From Week.”
    • Main visuals return BLANK (or show 0) until corrected.
    1. If valid, your visuals (table/chart counts, etc.) display results for rows where WeekNum is between From and To and also match selected Project/Phase.

    If you found this post helpful, please consider accepting it as the solution so that other members can find it more easily.

     

    Regards,

    Khashayar Yazdani | Microsoft MCT

    https://www.linkedin.com/in/khashayary/