Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
hichamou
New Member

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?

1 ACCEPTED SOLUTION
Poojara_D12
Super User
Super 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

  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

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 - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

View solution in original post

4 REPLIES 4
hichamou
New Member

It worked, Thanks Poojara.

@hichamou  Glad to hear that!! 🙂

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 - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
bhanu_gautam
Super User
Super 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.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Poojara_D12
Super User
Super 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

  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

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 - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.