Forum Discussion

hichamou's avatar
hichamou
New Member
1 year ago
Solved

Need help with RLS

  I have the following data table Name SS Last4 kiki 111111111 1111 sisi 222222222 2222 tito 333333333 3333       And Users Table Use...
  • Poojara_D12's avatar
    1 year ago

    Hi hichamou 

    To create a card that shows the SS for users with the role "ALL" and the Last4 for users with the role "Station", you can achieve this by creating a measure that uses conditional logic based on the user’s role.

    Here’s how you can set it up in DAX, assuming you have relationships between the tables or have set up a way to identify the logged-in user:

    Step 1: Create a Measure for Conditional Display

    1. Identify User Role: If you can identify the logged-in user, use their role from the Users Table.
    2. Create Conditional Measure: Use SWITCH or IF to conditionally display SS or Last4 based on the role.

    DAX Measure

    Assuming:

    • DataTable is your main table with columns SS and Last4.
    • Users Table contains User and Role.
    • You can identify the current user with a function like USERNAME() or via another filter.

    Here’s a sample DAX formula:

     

    DisplayValue = 
    VAR CurrentUser = SELECTEDVALUE('Users Table'[User])
    VAR UserRole = LOOKUPVALUE('Users Table'[Role], 'Users Table'[User], CurrentUser)
    
    RETURN
        SWITCH(
            TRUE(),
            UserRole = "ALL", MAX('DataTable'[SS]),
            UserRole = "Station", MAX('DataTable'[Last4]),
            BLANK()
        )

     

    Explanation

    1. CurrentUser: Retrieves the currently logged-in user.
    2. UserRole: Uses LOOKUPVALUE to find the role of the current user in the Users Table.
    3. SWITCH:
      • If the role is "ALL", it returns the SS value.
      • If the role is "Station", it returns the Last4 value.
      • If the role is neither, it returns blank.

    Step 2: Add the Measure to a Card Visual

    Add the DisplayValue measure to a card visual. Based on the role of the logged-in user, the card will display either the SS or Last4 value.

     

    This setup should dynamically adjust based on the role associated with the user viewing the report. Let me know if you need further assistance!

     

    Did I answer your question? Mark my post as a solution, this will help others!

    If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

    Kind Regards,
    Poojara
    Data Analyst | MSBI Developer | Power BI Consultant
    YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS