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
saif
Frequent Visitor

Measure to select one of the two columns based on Access and RLS

Hi,

 

I have a requirement where users depending on their Access can view one of the two columns ie either Account Number or Masked Account Number.

For eg: A user has access to 2 countries's data suppose USA and Canada. For USA he can view Account number but for Canada he would see Masked account number in the same column(Need help to write this measure).

Here is the sample data:

AccessControlAccessControlAllCountryAllCountryMasterDataMasterDataRelationshipRelationshipRls_1Rls_1RLS_2RLS_2

M Queries for source tables:
MasterData:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc4xCoAwDEbhu2Tu0ja1OnuMkgP8s/cHeUTUoY/wkUDXsrNaMd5FVC3Kgw0kaonMHSTqicwO+u8cHCCRJ7KwgUQjkYUJEs0P9/dLh0Xc", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, ID = _t, SomeImpColumn = _t, AnotherImpColumn = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"ID", Int64.Type}, {"SomeImpColumn", type text}, {"AnotherImpColumn", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"SomeImpColumn", "AccountNumber"}, {"AnotherImpColumn", "MaskedAccountNumber"}})
in
    #"Renamed Columns"

 

AccessControl:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjZUitUBUkYQyhhCmUAoUwhlphQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}})
in
    #"Changed Type"

 

AllCountry:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSjR0SNRLzs9V0lFyNgQSkUqxOqiiRkDCDyJqhBA1QYgaY1VrgmoupqgRwjYkUWOsapFsM8VqghlWX5hhdZkZqm2Yak2wippCTIgFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Email = _t, Country = _t, CanViewAccountNumber = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Email", type text}, {"Country", type text}})
in
    #"Changed Type"

 

RLS DAX:

 

[Country] 
IN 
SELECTCOLUMNS
(
   FILTER
   (
     AccessControl,
     AccessControl[Email]=USERPrincipalNAME()
    ),
  "Countries",
  AccessControl[Country]
)
[Email]=USERPRINCIPALNAME() 

 

 

Expected Outcome:

Output.PNG

Suppose a1@a.com logs in into power bi service, then he should see the below table :

Because for Country C1, the value of CanViewAccountNumber is yes, so the user gets value s1 and s2. But for country C2, the value of CanViewAccountNumber  is No so the user get the Masker Account number i3.

CountryIDAccountNumberAfterLogic
C11s1
C12s2
C23i3

 

Will appreciate any help in this.

2 REPLIES 2
amitchandak
Super User
Super User

@saif , have checked if Perspectives can help ?

https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-august-2020-feature-summary/#_Perspectives

 

masking

https://radacad.com/secure-the-sensitive-data-in-power-bi-data-masking-better-with-row-level-securit...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank You for yourresponse. Perspectives doesnt really match my use case.But Reza's blog does point me in the right direction. Currently working on it. Thank you again!

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.

Top Solution Authors