Forum Discussion
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
User | Role |
|
User1 | ALL |
|
User2 | Station |
|
|
|
|
I need to show a card with SS to all the Roles ALL and show Last4 to the role Station.
Can you help me with that?
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
- Identify User Role: If you can identify the logged-in user, use their role from the Users Table.
- 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
- CurrentUser: Retrieves the currently logged-in user.
- UserRole: Uses LOOKUPVALUE to find the role of the current user in the Users Table.
- 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
4 Replies
- Poojara_D12Super User
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
- Identify User Role: If you can identify the logged-in user, use their role from the Users Table.
- 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
- CurrentUser: Retrieves the currently logged-in user.
- UserRole: Uses LOOKUPVALUE to find the role of the current user in the Users Table.
- 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 - hichamouNew Member
It worked, Thanks Poojara.
- Poojara_D12Super User
hichamou Glad to hear that!! 🙂
- bhanu_gautamSuper User
hichamou Try using below steps
Ensure there is a relationship between the tables if necessary.
Create Measures: Create measures to display the SS or Last4 based on the user's role.
Use DAX for Conditional Display: Use DAX (Data Analysis Expressions) to create measures that conditionally display the SS or Last4 based on the role.
Here is an example of how you can create these measures:
SS_Display =
IF(
SELECTEDVALUE(Users[Role]) = "ALL",
SELECTEDVALUE(DataTable[SS]),
BLANK()
)
Last4_Display =
IF(
SELECTEDVALUE(Users[Role]) = "Station",
SELECTEDVALUE(DataTable[Last4]),
BLANK()
)
Create Cards: Add two card visuals to your report.Set the Measures: Set the first card to display the SS_Display measure and the second card to display the Last4_Display measure.
Filter the Cards: Ensure that the cards are filtered by the appropriate user role. You can use slicers or filters to control which user role is currently active.