Saturday, 10 February 2018

How to Create Row Level Security to restrict Users to View the Power BI Report

Row Level Security to restrict Users to View the Power BI Report
Row Level Security is a Security feature in Power BI Reports, that restricts the users to view the data in the report based on the User Roles assigned to their particular User Group.
Scenario:
If you want to allow the end users to view only the Sales in their specific Sales Region data, instead of viewing all regions, we can restrict them by defining the 
User Roles and assigning the Users to that User Group 

Example :
Suppose we have a Power BI Report , where we have the data of various Sales Regions like North America, Africa, Europe.




Now we will define the user roles on top of this report, based on the Sales_Region column as follows..

1) Go to Report tab Modeling  and then select the User Roles



2) Next Define the Team Name in Manage Roles and apply the required Filters on required Tables.
Here I have created to two Teams with below Filters on the Table vSalesByRegion :
Asia Team :
[Region_Name] = "Asia"

WorldWide_Team :
OR ([Region_Name]="Europe",[Region_Name]="North America")





3) Next validate the Roles by viewing the Report by defined Team Roles
View as Roles : Asia_Team:

Now the Report will shows only the Data for Asia Region as follows..

View as Roles : WorldWide_Team:
Now the Report will shows Data for Europe and North America Regions as follows..
4) Finally Publish the Report to Power BI Service and add the Users to the User Role Teams
Once we Publish Report to Power BI Service , we have to add the Users to the specific User Role Teams based on their Sales Region and requirement as follows..

In Power BI Service we will see the following things in the Work Space :
a) Dashboards
b) Reports
c) Datasets

Go to Datasets , then select our report Dataset on which we want apply the Row Level Security, as follows..

Click on the ...3dot icon next to the Dataset and then click on SECURITY option.
Next select the User Role Team ( Eg : Asia_Team) to add MEMBERS.
Next add the People or groups who belongs to this role, by specifying their email address.
Finally click Add.

Now People or groups who belongs to this role, will have access to view the data as per that Role definition we defined in Power BI Desktop Report.

Creating a Schedule Refresh Plan :
We can schedule the Power BI Reports to refresh automatically from Power BI Service

  • In the Work Space, right-click on the Power BI report and select Manage.
  • In the left menu, select the Scheduled refresh tab.
  • On the Scheduled refresh page, select New scheduled refresh plan.
  • On the New Scheduled Refresh Plan page, enter a description and set a schedule for when you want your data model to be refreshed.
  • Select Create scheduled refresh plan when done.

------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Anlytics Professional
--------------------------------------------------------------------------------------------------------

How to create and use Dynamic Query Parameters in Power BI Report

Creating and using Dynamic Query Parameters as a Filters in Power BI Report
Scenario:
If you want to allow the end users to Filter and view the Sales in their specific Sales Region data, instead of displaying all regions, we can do it by creating dynamic Parameter in the Report.
We can create a dynamic Query Parameter as follows..
Example :
Suppose we have a Power BI Report , where we have the data of various Sales Regions like North America, Africa, Europe.

 Now we will create a Dynamic Query Parameter based on the Sales_Region of the Query.
1) Go to Edit Queries

2) Create a Query List from Region_Name Column for using in Parameter
From Query Editor > Select column Region_Name from base Table and then R-click and choose the option as Add as new Query

Next Remove the Duplicates from the List, and rename the List

Now a unique List (DistRegion) has been ready to use in Parameter

3) Create a Dynamic Query Parameter using the above List
Go to Home > Manage Parameters > New Parameter

Next create a Parameter and select the suggested values from Query
Now the Parameter appears as follows

4) Apply Filter to the base Table using Parameter
Select the Column Region_Name then got Text Filters > Equals..

Next pass the Parameter as a value

Now the Parameter with the default value "Europe" has been applied to the Report. Please note that this Parameter value will apply dynamically based on user input.

Now Save, Close & Apply the Query Editor Window.

5) Save the Report as Template and Share that Template to the End Users
Once we created and apply the Dynamic Query Parameter, Save as the Report as Power BI Template, which we will share to the end users. This will prompt the users to Select their Sales Region to Load the Report.

Now, when a User opens the Template it will ask to select their Sales Region to View the Report 

Now if we select a Sales Region as Asia, the we will see only the "Asia" Region data as follows..

Important Notes:
Here user can choose and view any Region Data with no Restriction.This will NOT provide a Row Level Security.

If you want to Restrict the users to view only a specific Region data, we should Create and Define the Roles in Power BI Desktop then assign the People to those Roles in Power BI Service.We can also setup the Schedule Refresh in Power BI Service.




------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Anlytics Professional
--------------------------------------------------------------------------------------------------------

Tuesday, 30 January 2018

How to Update a Column based on Count of repeated Items in another Column in SQL Server

SQL Query to Update a Column based on Count of repeated Items in another Column
Scenario:
Suppose we have a table as follows
SELECT [Order_Id]
      ,[Geo_Id]
      ,[Cust_Name]
      ,[Sales_Region]
      ,[Deal_Id]
      ,[Net_Sales]
  FROM [dbo].[tbl_Sample]
GO



In this Table , we have to update the Column Geo_Id based on the following Conditions :
A). If we have only 2 Geo_Ids, one =-9999 and Other one <> -9999 ( Eg: -9999 , 1232 ) under the same Deal_Id ( Eg : 22222) Then we need to update the Geo_Id "-9999" with another Geo_Id , say 1232.

B). If we have only one Geo_Id , as -9999 under a Deal_Id ( Eg: 88888) then we should not perform any update.

C). If we have more than two Geo_Ids , one =-9999 and Others<> -9999  (Eg : -9999,1235 1236 ) under the same Deal_Id ( Eg : 77777) then we should not perform any update.

Now we can achieve this Scenario using the below Methods :

1) Sub Query Method :
Update [tbl_Sample]
Set  Geo_Id =S1.Geo_ID
From (
SELECT A.Order_Id,A.Geo_Id,A.Cust_Name,A.Sales_Region,B.Deal_Id,                                             A.Net_Sales,B.GeoCountByDeal
FROM [tbl_Sample] A
Inner Join (
SELECT COUNT(Distinct Geo_Id) as GeoCountByDeal, B.Deal_Id
         FROM [tbl_Sample] B
 GROUP BY B.Deal_Id
AS B 
    ON A.Deal_Id = B.Deal_Id
   WHERE GeoCountByDeal=2 and A.Geo_Id<>'-9999' 
   -- ORDER by A.Deal_Id
) S1
Where ( [tbl_Sample].Deal_Id=S1.Deal_Id and [tbl_Sample].Geo_Id=-9999 and S1.GeoCountByDeal=2 )
Select * From [tbl_Sample]
GO

2) Common Table Expressions (CTEs) Method :
WITH MyCTE
AS
(
SELECT A.Order_Id,A.Geo_Id,A.Cust_Name,A.Sales_Region,B.Deal_Id,                                             A.Net_Sales,B.GeoCountByDeal
FROM [tbl_Sample] A
Inner Join (
SELECT COUNT(Distinct Geo_Id) as GeoCountByDeal, B.Deal_Id
         FROM [tbl_Sample] B
 GROUP BY B.Deal_Id
AS B 
    ON A.Deal_Id = B.Deal_Id
   WHERE GeoCountByDeal=2 and A.Geo_Id<>'-9999' 
   -- ORDER by A.Deal_Id

Update [tbl_Sample]
Set  [tbl_Sample].Geo_Id =MyCTE.Geo_ID
From MyCTE
Where ( [tbl_Sample].Deal_Id=MyCTE.Deal_Id and [tbl_Sample].Geo_Id=-9999 and MyCTE.GeoCountByDeal=2 )
Select * From [tbl_Sample]
;
GO

Output after Update:



Thanks, TAMATAM

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts