Saturday, September 16, 2023

Row level Security in Tableau

In this tutorial, I'll explain row-level security in Tableau using the "Sample - Superstore" dataset, which is included with Tableau. Row-level security allows you to control data access for different users or groups within your organization. We'll cover four examples of row-level security using this dataset.


Example 1: Restricting Data by Region


Suppose you want to restrict data access based on the region assigned to each user. Users should only see data for their designated region.


Step 1: Data Preparation


Ensure your dataset includes a field that represents the region for each order, such as "Region."

Step 2: Create User Groups


In your Tableau Server or Tableau Online, create user groups corresponding to different regions (e.g., "West," "East," "Central," "South").

Step 3: Define Data Roles


Go to "Data" in the top menu and select "Data Roles."

Create a new data role, e.g., "Region Access."

Assign the data role to the relevant user groups (e.g., "West" group).

Define a filter condition in the data role by selecting "Region" and adding a condition like [Region] = USERGROUP().

Step 4: Apply Data Roles to Worksheets


In your Tableau workbook, apply the "Region Access" data role to the worksheets containing regional data. When a user from the "West" group logs in, they will only see data for the "West" region.

Example 2: Dynamic Row-Level Security with Parameters


Let's expand on the previous example by allowing users to choose a specific region using a parameter.


Step 1: Create a Parameter


Create a parameter named "Select Region" that allows users to choose a region.

Set the parameter data type to match the "Region" field in your dataset.

Step 2: Modify Data Roles


In the data role definition ("Region Access"), modify the filter condition to use the parameter value. For example, [Region] = [Select Region].

Step 3: Apply Data Roles with Parameters


In your worksheets, apply the "Region Access" data role with parameters. Users can choose a region from a parameter control, and the data displayed will be filtered accordingly.

Example 3: Manager-Subordinate Hierarchy


Imagine you have an organizational hierarchy in your company, and you want managers to access data for their team and subordinates.


Step 1: Data Preparation


Include a field in your dataset that represents the manager-subordinate relationship, such as "Manager ID."

Step 2: Create User Groups


Create user groups in Tableau corresponding to different managers or team leads.

Step 3: Define Data Roles


Create a data role, e.g., "Hierarchy Access."

Assign the data role to the relevant user groups (e.g., "Manager A" group).

Define a filter condition in the data role by selecting "Manager ID" and adding a condition like [Manager ID] = USERID() OR [Employee ID] = USERID().

Step 4: Apply Data Roles Hierarchically


In your worksheets, apply the "Hierarchy Access" data role. Managers will see data for their team and subordinates.

Example 4: Custom Row-Level Security with Database Integration


Suppose you want to integrate Tableau's row-level security with your database's security mechanisms.


Step 1: Database Integration


Integrate Tableau with your database's security features, such as database roles, views, or stored procedures that apply row-level security rules.

Step 2: Create User Groups


Create user groups in Tableau that align with the database security roles.

Step 3: Define Data Roles


Create a data role, e.g., "Custom Security."

Assign the data role to the relevant user groups.

In your database, implement the necessary logic to restrict data access based on the user's role or permissions.

Step 4: Apply Data Roles


In your Tableau worksheets, apply the "Custom Security" data role. Tableau will pass the user's credentials to the database, and the database will enforce row-level security based on the user's role.

By following these four examples using the "Sample - Superstore" dataset, you can understand how to implement row-level security in Tableau for various scenarios. Row-level security is a powerful feature that ensures data access control and protection while allowing users to view only the relevant information based on their roles or parameters.

Wednesday, September 13, 2023

Unlocking Precision: Tableau Exclude LOD Expressions Explained

Level of Detail (LOD) Expressions in Tableau allow you to perform calculations at different levels of granularity within your data without affecting the overall aggregation. In this tutorial, we'll focus on EXCLUDE LOD expressions, which allow you to exclude dimensions from the calculation, regardless of what's in the view. Here's a step-by-step tutorial with examples:

Example Data: We'll continue using the same dataset of sales transactions with columns: Order ID, Product, Category, Sales, Profit, and Region.

Tutorial: Using EXCLUDE Level of Detail (LOD) Expressions in Tableau

Step 1: Open Tableau and Connect to Your Data

Launch Tableau and connect to your dataset (e.g., Excel, CSV, database).

Step 2: Create a Simple Visualization

Drag the Category dimension to Rows and the Sales measure to Columns to create a bar chart showing total sales by category.

Step 3: Create an EXCLUDE LOD Expression

Right-click anywhere on a blank area in the calculated field pane and select "Create Calculated Field."

To create an EXCLUDE LOD expression, use the {EXCLUDE} keyword followed by the dimension(s) you want to exclude from the calculation. For example, let's create an LOD expression to calculate the average profit per product category while excluding the Region dimension:

{EXCLUDE [Region] : AVG([Profit])}

This expression tells Tableau to calculate the average profit per product category while excluding the Region dimension from the calculation.

Step 4: Use the EXCLUDE LOD Expression in a Visualization

Drag the EXCLUDE LOD expression you created (e.g., {EXCLUDE [Region] : AVG([Profit])}) to the Rows shelf alongside the Category dimension.

This will create a visualization that shows the average profit per category, excluding the Region dimension.

Step 5: Customize Your Visualization

Customize the visualization as needed by adding labels, colors, or other dimensions to enhance the presentation of the data.

Step 6: Understand the Results

Analyze the visualization. You'll see that the average profit per category is calculated while excluding the Region dimension. This means that the aggregation is done at the category level without considering the Region dimension.

Step 7: Create Additional EXCLUDE LOD Expressions

You can create more EXCLUDE LOD expressions as needed to perform calculations at various levels of detail in your data while excluding specific dimensions. For example, you could calculate the total sales per product category while excluding certain customer segments.

Step 8: Save and Share Your Workbook

Once you're satisfied with your visualization, save your Tableau workbook and share it with others as needed.

That's it! You've created an EXCLUDE Level of Detail (LOD) expression in Tableau to perform calculations that exclude specific dimensions from the calculation, regardless of what's displayed in the view. EXCLUDE LOD expressions are useful for fine-tuning your analysis by excluding certain dimensions while aggregating data, providing flexibility and control in your calculations.