Using RLS on secondary field to UserPrincipalName - powerbi

So if I have three users: Tom, Dick, and Harry, and they have been assigned group colors. I'd like them to be able to see everyone's data in their own group.
Name Group Email
----- ----- -----
Tom Green t#acme.com
Dick Red d#acme.com
Harry Red h#acme.com
So I create a measure
RLS_SecurityKey = CALCULATE(FIRSTNONBLANK(People[Group],People[Group]),
USERPRINCIPALNAME() = People[Email])
And when I log in as the separate users, I can see in a card visual that I'm getting the expected group.
But when I set row level security on the People table, [Group] = [RLS_SecurityKey], I only get back the one row that matches the email address and not the user that matches his Group.
It seems I'm missing something fairly apparent, but I can't see it. How can I get back all the rows relating to Group and not the email?

Yep, it was pretty straight forward.
RLS_SecurityKey = CALCULATE(FIRSTNONBLANK(People[Group],People[Group]),
FILTER(ALL('PEOPLE'),USERPRINCIPALNAME() = People[Email]))
I adjusted the filter expression and made it a proper filter over the whole table.

Related

Impossible to show all records if parameter is not given in Power Bi Report Builder

I've been struggling to make it work. I have a dataset with column Country and each record has its own country. I've also created a parameter #Country which is a blank input. What I want to do is to show all records from dataset if parameter is left empty and show records matching country when it is given by user. So far everything works whenever I input a country BUT when I leave it blank then no records are being shown. How can I fix it?
Snippets of code I've tried, ever one with the same result.
FILTER('Dataset', ISBLANK(#Country) || 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(ISBLANK(#Country), 1, 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(ISBLANK(#Country), 'Dataset'[Country], 'Dataset'[Country] = #Country))
FILTER('Dataset', IF(NOT(ISBLANK(#Country)), 'Dataset'[Country] = #Country, 1))

PowerBI Matrix Visual - Replacing Blank with Zero (harder than I thought)

I am trying to replace blanks with zero in a matrix visual, but the traditional method of adding +0 is causing another problem. I have the case described below in detail. Thank you so much for any help anyone may be able to offer!
I have a (fictitious) company with 60 employees located in 5 regions (Midwest, Northeast, Pacific, and Southwest). Each employee holds an occupational type (such as chemist, auditor, geologist, truck driver, etc.). Across the entire company, there are 18 different occupational types.
Additionally, each region considers some of the occupations as critical and others as non-critical and the critical vs. non-critical occupation types vary by region. If the occupation is critical for a particular region, the occupational title (e.g. chemist) should appear in the visual and if the occupation is non-critical, the generic title ‘Non-Critical’ should appear instead of the occupational title.
To accomplish this, my PowerBI model has two related tables – employee list (dimension table/many) and occupation list (fact table/one). Each employee on the employee list has a match code that is related to the match code on the occupation list to determine if the occupation is critical or non-critical for that employee’s region. If the occupation is critical, the related field (that will be used on the row field of the visual will be the occupational title. If non-critical, the related field will be the generic title ‘Non-Critical’.
Here’s an example of three records from the employee list fact table:
Image A
And here’s an example of some records from the occupational list dimension table:
Image B
The purpose of the visual is to show the count of employees onboard at two points in time (called FY20 and FY21) by occupational type with a slicer to filter by region.
The employee count is produced using the measure =COUNTROWS(Employee List)
Everything works great at this point. Here is an example of the visual filtered to Midwest, which correctly shows the Midwest Region’s 10 critical occupations broken out by occupational title and the employee counts. (non-critical count also correctly shown)
Image C
And as a second example, here is the view filtered to the Pacific Region showing the Pacific’s 3 critical occupations (non-critical also correctly show):
Image D
My only goal with this visual is to display zero instead of a blank for those cases where there are no employees. When I modify the measure to:
=COUNTROWS(Employee List) + 0
I get the following result (filtering to Midwest for example):
Image E
So, the result is that the formula did replace the blanks with zeros, but now all the entire company’s 18 critical occupations are displayed and not just the 10 for the Midwest. The counts are still correct for the Midwest, but I only want to show the Midwest occupations as they were appearing correctly before I added +0 to the measure. If I try to simply filter them out at the visual level, then they will stay filtered when I switch region where they should be unfiltered.
It seems the behavior is that a blank being replaced by a value (0) means that when there is a combination for which there is no data (such as Midwest/Chemist), the visual will still show 0 as a result for that combination.
I’m looking for anything I can do to replace blanks with zero and not displace the occupation types that don’t apply for the region. I would appreciate any assistance as I’ve been thinking about this for hours and have hit a wall.
Thank you!
I suggest a measure on the following form, written verbosely:
# Employees w/ zeroes =
VAR _employees = [# Employees]
VAR _totalEmployees = CALCULATE ( [# Employees] , REMOVEFILTERS ( 'Employee List'[Year] ) )
RETURN
_employees + IF ( ISNUMBER ( _totalEmployees ) , 0 )
This will first check that the occupation type has employees for the selected filter context, and only tack on a zero if so. The column specified in REMOVEFILTERS() must correspond to whatever you are using in your visualization - it is used to modify the filter context.
It looks like a fairly simple (if possibly temporary) solution is available for this problem by using conditional/advanced filtering on the visual. I set the advanced filter to show when the value is not 0 and this seemed to take care of it. Thank you for the DAX code and I will explore those options as well.
Thanks again!

Is it possible to create a formula that checks certain cells in a row against a lookup list and returns true/false value?

Here's a link to the spreadsheet for context. Essentially, here's what I'm trying to accomplish: In the tab titled 'Detailed Learning Report', I want column K to read "Complete" or "Incomplete" based on criteria. So, for example, for row 2, I want to check which site the UID is connected to and, depending on if it's Bedford, San Bernardino or Lithonia, determine if that user completed all required courses for that site. I have a breakdown of which courses are required per site on the tab titled 'Sheet 3'. Ultimately, at the end of this, I want a unique list of users (that's the unique list you see on the 'Sheet 3') and either "Complete" if all the required courses are marked completed in the 'Detailed Learning Report' tab or "Incomplete" if not. I'm not even sure if this is possible so I appreciate your help!
use:
=ARRAYFORMULA(IF(E2:E="",,
IF((E2:E="BEDFORD PARK IL")*
(H2:H="COMPLETE")*
((F2:F=Sheet3!I2)+
(F2:F=Sheet3!I3)+
(F2:F=Sheet3!I4)+
(F2:F=Sheet3!I5)), "COMPLETE",
IF((E2:E="SAN BERNARDINO CA")*
(H2:H="COMPLETE")*
((F2:F=Sheet3!I5)+
(F2:F=Sheet3!I7)+
(F2:F=Sheet3!I8)), "COMPLETE", "INCOMPLETE"))))
((F2:F=Sheet3!I2)+
(F2:F=Sheet3!I3)+
(F2:F=Sheet3!I4)+
(F2:F=Sheet3!I5))
can be shortened to:
(REGEXMATCH(F2:F, TEXTJOIN("|", 1, Sheet3!I2:I5)))

PowerBI Desktop - Identifying Common Items that belongs to the Selected Values in a column

I am trying to do some analytics on PowerBI. I am struck at this logic, where I am trying to Identify the common items with in the group and not common items with in the group.
For Example,
Group Name Contact
GroupA Rock
GroupA Eddy
GroupA Brown
GroupB Rock
GroupB Katie
GroupC Eddy
GroupC Brown
GroupC Katie
If I select GroupA and GroupB then I want to output the Common Items as 1 and not common Items as 3.
The Common Item is Rock
The Not Common Items are Eddy, Brown & Katie.( I am looking to get this as part of my output visual as well)
How can we do this in PowerBI which works dynamically when we select multiple groups (more than 2 as well)?
I would approach this by checking if the number of groups the Contact appears in is the same as the number of groups that you have selected:
Common = IF(COUNTROWS(VALUES(Groups[Group Name])) =
COUNTROWS(CALCULATETABLE(VALUES(Groups[Group Name]),
ALLSELECTED(Groups))),
"Common", "Not Common")
Then you can use these labels inside a second measure to get the count:
Intersect = IF([Common] = "Common",
CALCULATE(DISTINCTCOUNT(Groups[Contact]),
FILTER(ALLSELECTED(Groups[Contact]), [Common] = "Common")),
CALCULATE(DISTINCTCOUNT(Groups[Contact]),
FILTER(ALLSELECTED(Groups[Contact]), [Common] = "Not Common")))
You can then set up a table or matrix using Contact and the new measure Intersect along with a slicer on Group Name.

How to add Region / State in opencart checkout?

Please suggest a way to add an extra Region /State in checkout which is not there in Opencart default .
You can add region for any country from admin panel also.
settings->localisation->zone
The region/states are in the oc_zone table. You can add extra entries into this table but make sure you get the right country code and put that into the record too.
The country codes are in the oc_country table.
So, for example, if you wanted to add a new Region called "The People's Republic of Cleckheaton" to the United Kingdom, first look up the country code for the United Kingdom in oc_country. The code is 222.
Then you can add the new zone to oc_zone with something like the following:
INSERT INTO `oc_zone` (`zone_id`, `country_id`, `name`, `code`, `status`) VALUES (NULL, '222', 'The Peoples Republic of Cleckheaton', 'PRC', '1');
Finally there's another slight issue. Opencart actually caches all the country and zone data so if you add a new field like this it probably won't show up because the old data will be cached.
You should probably be able to fix this by clearing your browser's cache but failing that update the following line in \catalog\model\localisation\zone.php Warning: This is in opencart 1.5.6 but should be similar in 2.0
$zone_data = $this->cache->get('zone.' . (int)$country_id);
to
zone_data = false;
Once you've confirmed it's working ok update that line back to it's original content.