Default filter in Power BI - Row Level Security not applied through LOOKUPVALUE

房东的猫 提交于 2019-12-05 22:23:21

I see what you mean now. LOOKUPVALUE appears to have unfiltered access to your table, bypassing RLS. I'd suggest reporting this to Microsoft as a bug.

In your report, I'd suggest using measures of this form:

Measure =
VAR EmployeeLocation =
        LOOKUPVALUE(Employee[LocationKey],
                    Employee[UserPrincipalName],
                     USERPRINCIPALNAME())
RETURN IF(ISFILTERED(Location[Location]),
           <expression>,
           CALCULATE(<expression>,
               FILTER(Location, Location[LocationKey] = EmployeeLocation)))

That way it should default to calculating values for EmployeeLocation when Location is left unfiltered and will behave normally otherwise.

This is working for me so far:

The objective is to have a given user automatically see their own location, but have the option to see other locations.

I tried many things but eventually I just went to creating separate measures on the fact table that refer directly to USERPRINCIPALNAME

i.e. this shows the location total units against the users location and zero against everything else.

    My Location Units:= 
        CALCULATE(
            SUM([Units]),
            FILTER(
                'Location',
                'Location'[LocationKey]=
                LOOKUPVALUE(
                    'Employee'[LocationKey],
                    'Employee'[UserPrincipalName],
                    USERPRINCIPALNAME()
                )
            )
        )

Then I thought: can't I just use this on a dimension?

Is My Location:= 
    CALCULATE(
    IF(ISBLANK(MAX('Location'[LocationKey])),"No","Yes"),
    FILTER(
        'Location',
        'Location'[LocationKey]=
        LOOKUPVALUE(
            'Employee'[LocationKey],
            'Employee'[UserPrincipalName],
            USERPRINCIPALNAME()
        )
    )
)

Even though I need to use this at a row level, it appears to work even though it is a measure.

It uses CALCULATE(<expression>,FILTER(<table>,<expression>))

The FILTER part does the user level filtering

The expression part turns that into YES/NO

And I can use it to filter in Power BI and pick only the current users location if I want.

I suspect all of these expressions ban be written more simply. Feel free to enlighten me

I still don't know why LOOKUPVALUE does not respect RLS. I'd like to know if it does, but I've done something wrong, or if it doesn't.

As I understand it, Lookup[LookupValue] is a Column (not a Measure), using your 3rd code snippet: "=LOOKUPVALUE( ..."

The results of Calculated Columns like that are materialized when you Refresh the model. They are not affected by RLS which is applied at query time, just before the Measures are calculated.

This is not specific to the LOOKUPVALUE function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!