Forum Discussion

SensingFailure's avatar
SensingFailure
Frequent Visitor
2 years ago
Solved

How to Create Dynamic Default Slicer Value?

I have been following the steps from this post on creating a default slicer selection based on a user's location.   Everything appears to be working correctly except I am unable to place the Visual...
  • SensingFailure's avatar
    SensingFailure
    2 years ago

    I actually was able to crack this problem!  I will attempt to break down how I achieved this.

    I created a Slicer Table with:

    Slicer Table = 
    UNION(
        SELECTCOLUMNS(
            'ORION - Posts',
            "PostName", 'ORION - Posts'[PostName]
        ),
        DATATABLE(
            "PostName", STRING,
            {{"Current Post"}}
        )
    )

    Then I have a user table with the locations tied to their principal user names by email and use this measure to lookup the post name:

    UserPostName = 
    LOOKUPVALUE(
        'UserLocationData'[PostName],
        'UserLocationData'[email], USERPRINCIPALNAME()
    )

    Back in the Slicer Table, I created another measure to use the user's post name if "Current Post" is selected in the slicer.

    SelectedPostName = 
    IF(
        SELECTEDVALUE('Slicer Table'[PostName]) = "Current Post",
        [UserPostName],
        SELECTEDVALUE('Slicer Table'[PostName])
    )

    The biggest issue I was having was that other measures would not calculate correctly.  This is solved by adding a variable into each measure.

    LES Count = 
    VAR SelectedPost = 
        IF(
            SELECTEDVALUE('Slicer Table'[PostName]) = "Current Post",
            [UserPostName],
            SELECTEDVALUE('Slicer Table'[PostName])
        )
    
    VAR EmpCount = 
        CALCULATE(
            SUM('DAFI - Personnel Data'[count]),
            'DAFI - Personnel Data'[employeeType] = "Locally Employed Staff (LE Staff)",
            'DAFI - Personnel Data'[site] = SelectedPost
        )
        
    RETURN
    IF(ISBLANK(EmpCount), 0, EmpCount)

    However, I had to deactivate the relationships for:

    • 'Slicer Table'[PostName] to 'ORION - Posts'[PostName]
    • 'UserLocationData'[PostName] to 'ORION - Posts'[PostName]