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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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...

Share with Power BI Enthusiasts: 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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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