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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

From SQL to DAX

I want to filter a table when: 

 

Id in
(select EntityId from ShipmentItemPermissionGroup sipg
join PermissionGroup pg on pg.Id = sipg.PermissionGroupId
join UserPermissionGroup upg on upg.PermissionGroupId = pg.Id
join [User] u on u.Id = upg.UserId
where u.Username = 'username')

I am adding this for Role permissions. I have tried various ways but unable to get this to work. Can someone suggest a solution for this? 

 

Thanks!

1 ACCEPTED SOLUTION

Hi @Anonymous

For this SQL statement, i could obtain a JOIN behavior in DAX using the relationships in data model.


 

select EntityId from ShipmentItemPermissionGroup sipg
join PermissionGroup pg on pg.Id = sipg.PermissionGroupId
join UserPermissionGroup upg on upg.PermissionGroupId = pg.Id
join [User] u on u.Id = upg.UserId
where u.Username = 'username'

edit relationships between the four tables used in the statement based on 

UserPermissionGroup[UserId]<->User[Id]

UserPermissionGroup[PermissionGroupId]<->PermissionGroup [Id]

PermissionGroup [Id]<->ShipmentItemPermissionGroup[PermissionGroupId]

 

Then click on "New Table", enter the formula below

Table =
SELECTCOLUMNS (
    FILTER (
        SUMMARIZE (
            ShipmentItemPermissionGroup,
            ShipmentItemPermissionGroup[EntityId],
            User[name]
        ),
        [name] = "a"
    ),
    "id", [EntityId]
)

Best Regards

maggie

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @Anonymous

From you SQL statement, it seems you are seeking for the ways to join tables and filter the id which meets the conditions, then finally to apply this filter id for RLS.

Please refer to the following articles. If you have difficulties in implementing this in your scenario, please share some data and expected results so that i can analyze for you effeciently.

Join tables:from SQL to DAX

RLS with power bi

 

Best Regards

Maggie

 

Anonymous
Not applicable

Hi Maggie,

 

Thanks for your response, I am able to get to the penultimate step but the last join is feeling impossible:

 

[PermissionGroupId] IN (SELECTCOLUMNS
(FILTER(CROSSJOIN(User, UserPermissionGroup), User[Id] = UserPermissionGroup[UserId] && User[Username]="username"), "PermissionGroupId",[PermissionGroupId]))

I want to do a further join on PermissionGroupId to ShipmentItemPermissionGroup.PermissionGroupId but do not know how to do it. 

 

Original query: 

Id in
(select EntityId from ShipmentItemPermissionGroup sipg
join PermissionGroup pg on pg.Id = sipg.PermissionGroupId
join UserPermissionGroup upg on upg.PermissionGroupId = pg.Id
join [User] u on u.Id = upg.UserId
where u.Username = 'username')

 

Please help. Thanks!

Hi @Anonymous

For this SQL statement, i could obtain a JOIN behavior in DAX using the relationships in data model.


 

select EntityId from ShipmentItemPermissionGroup sipg
join PermissionGroup pg on pg.Id = sipg.PermissionGroupId
join UserPermissionGroup upg on upg.PermissionGroupId = pg.Id
join [User] u on u.Id = upg.UserId
where u.Username = 'username'

edit relationships between the four tables used in the statement based on 

UserPermissionGroup[UserId]<->User[Id]

UserPermissionGroup[PermissionGroupId]<->PermissionGroup [Id]

PermissionGroup [Id]<->ShipmentItemPermissionGroup[PermissionGroupId]

 

Then click on "New Table", enter the formula below

Table =
SELECTCOLUMNS (
    FILTER (
        SUMMARIZE (
            ShipmentItemPermissionGroup,
            ShipmentItemPermissionGroup[EntityId],
            User[name]
        ),
        [name] = "a"
    ),
    "id", [EntityId]
)

Best Regards

maggie

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors