Setting Row level security with multiple columns in Power BI - powerbi

I am trying to create a filter for target table having country code column. I want to give access to people with logged in upn either in AdditionalOwner or OwnerEmail with countrycode
AdditionalOwner has emails separated by commas, Number of emails in additionalowner column is not fixed also it may have values from OwnerEmail column. So Please help me in giving RLS in this scenario
Please find my column structure
CountryCode
AdditionalOwner
OwnerEmail
AU
test1#test.com,test2#test.com
test2#test.com
Here is the DAX I have used for Owner Email
[Country Code] = LOOKUPVALUE(
UserRoles[CountryCode],
UserRoles[OwnerEmail],UserPrincipalName())
Please help me in adding RLS for AdditionalOwner column too

You may want to try using something like OR, IF, and CONTAINSSTRING in your managed role. I've included an example for you to test below. For transparency, I did not test this but this is where I would start to solve this.
OR (
UserRoles[CountryCode] =
IF(
CONTAINSSTRING ( UserRoles[AdditionalOwner], UserPrincipalName() )
, UserRoles[CountryCode], BLANK() )
, UserRoles[CountryCode] = LOOKUPVALUE(
UserRoles[CountryCode],
UserRoles[OwnerEmail], UserPrincipalName())
)

Related

How to filter a dimension based on RLS applied to another dimension?

Assume I have 2 dimension tables and 1 fact table.
DimUser
DimClients
DimCompany
FactSales
All the dims have a 1:M relation with filter flowing from the 1 -> M side.
Assume I have configured RLS filter on DimUser ([Username] = USERNAME()) so that the user of the report can see his own data based on email address, so user can see his own record entry in DimUser. Thus it will auto filter the FactSales also, effectively the user will be able to see only his sales.
However the user can see all clients and companies in the slicer. I want to setup filter on the DimClients and DimCompany so that the user can see only clients and conpanies for which he has made sales. How can I achieve this?
For example:
How to apply RLS to the DimClients and DimCompany so that it will filter only those ClientIds that appear in the sales table based on dynamic filter [Username] = USERNAME() applied on the DimUsers table?
The other option is to enable bidirectional filtering but this is not allowed for multiple tables.
You can create a measure that looks like this:
UserFlag =
CONTAINSSTRING (
CONCATENATEX ( FactSales, RELATED ( DimUsers[UserEmail] ), "," ),
USERNAME()
)
Create your RLS role and add this filter to each dimension.
[UserFlag] = True()
The result: If a row from a dimension is related to a fact row that is in turn related to the DimUser row whose email matches USERNAME(), then the measure returns 'True.' And so RLS is filtering only to those rows.

Using Power BI to report who HASN'T logged on

A little bit of a newbie with Power BI DAX code. I have a log database that has two tables, Connections, and Employees. The two tables have a one-to-many relationship on sEmailAddress. The following DAX code that creates metrics works well in that I get a count of my employees that connect via VPN and I can get a list of those that connect via VPN
sVPN Count =
CALCULATE (
DISTINCTCOUNT ( Connections[sEmailAddress] ),
FILTER ( Connections, Connections[sTarget] = "VPN" ),
FILTER ( Connections, Connections[sEvent] = "User Logon" )
)
sVPN Users =
CALCULATETABLE (
DISTINCT ( Connections[sEmailAddress] ),
FILTER ( Connections, Connections[sTarget] = "VPN" ),
FILTER ( Connections, Connections[sEvent] = "User Logon" )
)
I am trying to find a method that can provide me a list of employees that DON'T login on any given day.
You are created a Calculated Column/ Measure, but you put calculation that is returning a table of value. If you need only a list of email, then put your code to "New Table". Then just add this newly created column to your visual.
If you need to show this with additional data, then you can create a column with a flag (1/0) based on your relationship.
pseudo using IF
Flag = IF(isblank('left side of relationship'), 1,0)
One approach would be to add a calculated column to your employee table where you use the [sVPN Count] measure you've already defined. Then you can identify the employees who haven't logged in by seeing which rows have blank or zero values in that column.
As msta42a notes, a measure can only return a single value, not a table. (This is the reason for the error you are getting.)

New Column is Doubling Value Based on Nested If Formula

I have a table that looks like this. Table Screenshot
"FY 20-21 (Budgeted)", "FY21 Approved Budget" and "Revised Budget" are columns coming from three different data sources that I appended into one table. There isn't always data in all three of these columns, so I created a new column to consolidate the data with the following formula:
FY 20-21 Budget =
if(
and(
isblank('Comprehensive Budget'[FY 20-21 (Budgeted)]),
isblank('Comprehensive Budget'[FY21 Approved Budget])
),
'Comprehensive Budget'[Revised Budget],
if(
and(
isblank('Comprehensive Budget'[FY21 Approved Budget]),
isblank('Comprehensive Budget'[Revised Budget])
),
'Comprehensive Budget'[FY 20-21 (Budgeted)],
'Comprehensive Budget'[Revised Budget]
)
)
If both Budgeted and Approved are blank, use Revised.
If not, if both Revised and Approved are blank, use Budgeted.
If not, use Revised.
But if you look on the screenshot, if NONE of the columns are blank, it gives me Revised plus Budgeted. Where is the problem in my formula?
I have added your data here and found your Measure is perfectly returning your expected data as shown in the below image-
I Guess, there are some Aggregation issue in your case. You can right click on all column in the table visual properties and select Don't Summarize from the options. This should solve your issue I hope.

Power BI - Show only data that belongs to the required selection (And Logic)

I have a table like this
Role Skills Resource
Data Analyst R A
Data Analyst Python A
Data Analyst SQL B
Business Analyst SQL A
My Skills are on filter. I have multiple visuals on the dashboard.
And If I select SQL and Python then the results of both Data Analyst and Business Analysts are getting displayed in the visual.
But, I want it to display only the Data Analyst results because only Data Analyst has all the selected skills.
To achieve this, I think of creating a measure and putting it on visual level filter in each of the visual might help.
Update :- If I select SQL here, I get 2 distinct resources on my card visual which is relevant to resources, but If I select SQL and Python - I get 0 Resources on my card visual which is relevant to resources and 1 role count which is relevant to roles on the Role measure.
Kindly help me with creating that measure.
Perhaps someone will suggest a more elegant way to do it; I came up with the following ideas.
Create a measure (I'll call your table "Data"):
Has All Selected Skills
=
VAR
Selected_Skills = ALLSELECTED ( Data[Skills] )
VAR
Role_Skills = CALCULATETABLE ( VALUES ( Data[Skills] ), ALL ( Data[Skills] ) )
VAR
Missing_Skills = COUNTROWS ( EXCEPT ( Selected_Skills, Role_Skills ) )
RETURN
IF ( NOT ( Missing_Skills ), 1 )
If the measure is placed in a visual against Roles, it'll produce the following results:
The way this code works:
First, we store all selected skills in a variable "Selected_Skills";
Second, we store all skills available for a role in a variable "Role_Skills". We must use ALL(Data[Skill]) to ignore the skill slicer selections;
Third, since both variables above are tables, we can use EXCEPT function to find how they are different. Here, we tell DAX to find what records in Selected_Skills don't exist in Role_Skills. Store the result in a variable "Missing_Skills".
Finally, if Missing_Skills is zero, it means that the role has all selected skills, and we flag it as 1 (although you might use True/False, etc).
The problem I see with this approach is that if Skill selector has no selection (shows "all skills"), then the formula might return blank for all roles, and all your visuals will be blank. Technically, it's correct - it's essentially saying that no roles have all skills. But if that's not the behavior you want, consider a slightly modified approach:
Missing Skills Count
=
VAR
Selected_Skills = ALLSELECTED ( Data[Skills] )
VAR
Role_Skills = CALCULATETABLE ( VALUES ( Data[Skills] ), ALL ( Data[Skills] ) )
VAR
Missing_Skills = COUNTROWS ( EXCEPT ( Selected_Skills, Role_Skills ) )
RETURN
Missing_Skills + 0
The formula uses the same logic, only returns the number of missing skills per role, instead of a true/false status. It will allow you to show a list of skills, sorted by the number of missing skills vs the selected skill set:
You can still use it to filter your visuals; the advantage is that it's never blank, even if all skills are selected:
It also gives you a capability to see what roles are the closest to meeting the requirement, even if none matches it perfectly; might be a desirable feature.
Final note: in all these reports, I have no subtotals and totals, assuming that they are not important. If you do need them, then the formulas might need to be modified to meet your requirements for the totals (depending on what you want to show there).

PowerBI - Use Value in Table View as Filter Parameter

This doesn't seem like it should be too complicated, but I'm not quite sure how to get it working.
I have a table in PowerBI with the following columns:
The columns in the database have an entry for Submitter and QAer
The QAs Posted column is basically just a COUNT of the Submitter
For QAs Pulled, I need to get the count of rows where the particular Submitter (in the first column) is listed as the QAer.
Is this something I can do?
Any help is appreciated, thanks!
EDIT: More about the data model - here's a screenshot example.
I think you are looking for something like this:
Measure =
COUNTROWS (
FILTER (
ALL( 'datatabel' ),
'datatabel'[QAer] = SELECTEDVALUE ( 'datatabel'[Submitter] )
)
)