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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
BartHuls
Helper I
Helper I

How do set the Row-level Security roles within the PowerBiClient SDK

All,
WithIn the PowerBiClient SDK I want to update / set  a Row-level Security roles.
The Group will then be visible in underlying screen.

Thanks in advance

 

BartHuls_0-1744122595113.png

 

1 ACCEPTED SOLUTION
BartHuls
Helper I
Helper I

This cannot be done by the PowerBIClient SDK.

For now I have the following solution. It's not nice, but it works. based on the Microsoft.AnalysisServices.Tabular lib.

public async Task SetRowLevelSecurity(string groupName, string datasetId, Guid domainGroupId, string domainName, string tenantId)
    {
        _authenticationResult ??= await GetAccessToken();

        var dataSource = $"powerbi://api.powerbi.com/v1.0/{domainName}/{groupName}";

        using var server = new Server();
        server.Connect($"DataSource={dataSource};Password={_authenticationResult.AccessToken}");

        var database = server.Databases.Find(datasetId) ?? throw new NullReferenceException(_cannotFindDataSet);

        // Cast is needed otherwise the loading does not work
        var model = (Model)database.Model;
        var role = model.Roles.Find(<RoleName>);
        if (role is not null)
        {
            var memberName = $"obj:{domainGroupId}@{tenantId}";
            var member = role.Members.FirstOrDefault(m => m.Name.Contains(memberName, StringComparison.OrdinalIgnoreCase));
            if (member is not null)
            {
                return;
            }

            role.Members.Add(new ExternalModelRoleMember
            {
                MemberName = memberName,
                MemberType = RoleMemberType.Group,
                IdentityProvider = "AzureAD"
            });
            database.Model.SaveChanges();

            logger.LogInformation("Row Level Security set for {GroupId} for dataset {DataSetId}", domainGroupId, datasetId);
        }
    }



View solution in original post

5 REPLIES 5
BartHuls
Helper I
Helper I

This cannot be done by the PowerBIClient SDK.

For now I have the following solution. It's not nice, but it works. based on the Microsoft.AnalysisServices.Tabular lib.

public async Task SetRowLevelSecurity(string groupName, string datasetId, Guid domainGroupId, string domainName, string tenantId)
    {
        _authenticationResult ??= await GetAccessToken();

        var dataSource = $"powerbi://api.powerbi.com/v1.0/{domainName}/{groupName}";

        using var server = new Server();
        server.Connect($"DataSource={dataSource};Password={_authenticationResult.AccessToken}");

        var database = server.Databases.Find(datasetId) ?? throw new NullReferenceException(_cannotFindDataSet);

        // Cast is needed otherwise the loading does not work
        var model = (Model)database.Model;
        var role = model.Roles.Find(<RoleName>);
        if (role is not null)
        {
            var memberName = $"obj:{domainGroupId}@{tenantId}";
            var member = role.Members.FirstOrDefault(m => m.Name.Contains(memberName, StringComparison.OrdinalIgnoreCase));
            if (member is not null)
            {
                return;
            }

            role.Members.Add(new ExternalModelRoleMember
            {
                MemberName = memberName,
                MemberType = RoleMemberType.Group,
                IdentityProvider = "AzureAD"
            });
            database.Model.SaveChanges();

            logger.LogInformation("Row Level Security set for {GroupId} for dataset {DataSetId}", domainGroupId, datasetId);
        }
    }



v-csrikanth
Community Support
Community Support

Hi @BartHuls 
Please do raise your new thoughts in the ideas forum and upvote it so that it will be adressed by the Microsoft internal team.

Best Regards,
Community Support Team _ C Srikanth.

lbendlin
Super User
Super User

Not currently available in any of the APIs. If this is important to you please consider voting for an existing idea or raising a new one at https://ideas.fabric.microsoft.com

Is there a way to set this from the outside? how to a access a xmla endpoint

If this is important to you please consider voting for an existing idea or raising a new one at https://ideas.fabric.microsoft.com

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.