PowerBI (1 Interview)
PowerBI (1 Interview)
Import Mode:
In import mode, data from the data source is loaded into Power BI's internal data
model.
Power BI compresses and stores the data within the PBIX file (Power BI file).
All data transformations, calculations, and modeling are performed within Power
BI's memory.
This mode is suitable for smaller datasets or when you need to perform complex
calculations on the data.
Refreshing the data involves reloading the entire dataset from the source.
DirectQuery Mode:
In DirectQuery mode, Power BI sends queries directly to the data source whenever
you interact with visualizations.
Data remains in the data source, and Power BI retrieves only the necessary data for
visualization and analysis.
There's no need to load data into Power BI's memory, making it suitable for large
datasets.
Since data stays in the source system, reports reflect real-time data changes.
Complex calculations and transformations may need to be performed in the source
system.
Performance depends on the speed of the data source and the network connection.
In summary, while import mode brings data into Power BI for analysis and
visualization, DirectQuery mode keeps the data in the source system and queries it
as needed. The choice between them depends on factors such as data size,
performance requirements, need for real-time data, and data source capabilities.
Power Query allows you to create custom columns using formulas similar to Excel.
You can also define custom functions using the M language to perform advanced
transformations or calculations.
Data Profiling:
Power Query provides data profiling capabilities to analyze the quality and
characteristics of your data.
You can identify data types, null values, unique values, and data distribution to
better understand your data.
Query Folding:
Power Query includes features for handling errors and exceptions during data
transformation.
You can specify how to handle errors, such as replacing values, ignoring errors, or
raising custom errors.
Parameterization:
Get Data: Click on the "Get Data" button in the Home tab of the ribbon. This will
open a dialog box where you can select the data source for your new table. You can
choose from various data sources like Excel, CSV, SQL Server, etc. For this
example, let's assume you want to create a table manually without importing data
from an external source.
Enter Data: In the Get Data dialog, select "Enter Data" option, then click
"Connect". This will open the "Enter Data" window.
Define Columns and Values: In the "Enter Data" window, you can define the columns
and manually enter the data values. Click on the "Add Column" button to add new
columns, and enter the column names and corresponding values in the table grid.
Load Data: Once you've entered the data, click on the "Load" button to load the
table into Power BI. Alternatively, you can click on "Transform Data" if you want
to perform additional data transformations before loading the data.
Data Model View: After loading the data, you can switch to the "Data" view in Power
BI to see your newly created table along with other tables in the data model.
Use in Reports: You can now use the newly created table in your Power BI reports.
Drag and drop fields from the new table onto the report canvas to create
visualizations, or use them in calculations and measures.
That's it! You have successfully created a new table in Power BI. You can continue
to refine and enhance your data model by adding more tables, relationships, and
calculations as needed.
Go to Data view: Click on the "Data" view icon on the left side of the Power BI
Desktop window. This will switch to the Data view where you can see your existing
tables and relationships.
Modeling Tab: Click on the "Modeling" tab at the top of the Power BI Desktop
window.
New Table: In the Modeling tab, click on the "New Table" button in the "Tables"
group. This will create a new blank table in the data model.
Define Columns: Once you've created the new table, you can define its columns by
typing column names directly into the table. Press "Enter" after typing each column
name to add it to the table.
Enter Data: You can then manually enter data into the blank table by clicking on
each cell and typing in the values. Press "Enter" to move to the next cell.
Load Data: After entering the data, click on the "Close & Apply" button in the Home
tab to save your changes and load the data model.
Use in Reports: You can now use the blank table in your Power BI reports just like
any other table. You can create visualizations, add calculated columns, and define
measures using the data in the blank table.
That's it! You have successfully created a blank table in Power BI without
importing data from an external source. You can continue to work with the table and
add more data as needed.
Here's a simplified example of how you can apply conditional formatting in Power
Query:
Open Power BI Desktop and load your data into Power Query.
Transform Data: Perform any necessary data transformations in Power Query. For
example, you might filter rows, add columns, or perform calculations.
Create Conditional Columns: Use conditional logic (if statements) to create new
columns based on your criteria. For instance, you can create a column that flags
rows meeting certain conditions.
m
Copy code
if [Sales] > 1000 then "High"
else if [Sales] > 500 then "Medium"
else "Low"
Load Data: After applying your transformations, load the data into Power BI.
By performing conditional logic in Power Query before loading your data into Power
BI, you can prepare your data to be easily formatted based on various conditions
once it's in your report. Keep in mind that Power Query's primary purpose is data
transformation, and conditional formatting is generally applied in visualization
tools like Power BI or Excel.
Get Data:
After connecting to your data sources, Power BI will open the Power Query Editor.
In the Power Query Editor, you can perform data transformations such as filtering
rows, renaming columns, removing duplicates, creating calculated columns, and
merging tables.
Click on the "Close & Load" button to load the transformed data into Power BI.
Create Relationships:
Once your data is loaded into Power BI, navigate to the "Data" view by clicking on
the "Data" icon on the left side of the Power BI Desktop window.
In the "Data" view, you'll see a list of tables that you've imported.
To create relationships between tables, click on the "Modeling" tab at the top of
the Power BI Desktop window.
Click on "Manage Relationships" in the Modeling tab.
In the Manage Relationships dialog, click on "New" to create a new relationship.
Choose the primary and foreign keys for each table you want to relate. Power BI
will automatically detect common columns, but you can also manually specify the
relationship if needed.
Define Calculated Columns and Measures:
In the Data view, you can create calculated columns and measures using DAX (Data
Analysis Expressions) language.
Click on the "New Column" or "New Measure" buttons in the Modeling tab to create
new calculated columns or measures, respectively.
Write DAX expressions to define the logic for your calculated columns and measures.
Build Visualizations:
Switch to the "Report" view by clicking on the "Report" icon on the left side of
the Power BI Desktop window.
Use the fields from your data model to create visualizations such as charts,
tables, matrices, and maps.
Drag and drop fields onto the canvas to create visualizations, and customize them
using formatting options and visual properties.
Save and Publish:
Once you've created your data model and visualizations, save your Power BI file
(.pbix).
You can then publish your report to the Power BI service to share it with others or
schedule data refreshes if your data sources are online.
By following these steps, you can create a data model in Power BI that combines
data from different sources, shapes and transforms it, creates relationships
between tables, and builds interactive visualizations for analysis and reporting.
Active Relationships:
Inactive relationships are additional relationships that you can create between
tables.
These relationships are not used by default in calculations and visuals.
Inactive relationships are useful for scenarios where you need to perform analysis
based on different criteria or for creating more complex calculations.
Inactive relationships are denoted by a dashed line in the relationship view.
Here's how you can use inactive relationships in Power BI:
Create Inactive Relationships:
You can use inactive relationships in DAX calculations by explicitly specifying the
relationship using the USERELATIONSHIP function.
For example, if you have an active relationship between Date and Sales, but you
want to analyze sales based on a different date column (e.g., Ship Date), you can
create an inactive relationship between Date and Ship Date. Then, in your DAX
calculations, you can specify the inactive relationship using the USERELATIONSHIP
function.
Use Inactive Relationships in Visuals:
You can also use inactive relationships in visuals by creating measures that
explicitly use the inactive relationship.
When creating a visual, you can drag and drop fields from both tables onto the
canvas and then use measures that reference the inactive relationship to perform
analysis based on that relationship.
By using both active and inactive relationships in your data model, you can handle
more complex analysis scenarios and perform calculations based on different
criteria within Power BI.
As mentioned earlier, you can have both active and inactive relationships between
tables. In the context of multiple relationships involving the same table, you
might have one relationship active and the others inactive.
Differentiating Relationships:
When creating multiple relationships involving the same table, it's essential to
differentiate them, either by using different column names or by making use of
roles. Roles are a way to distinguish between different relationships.
Using Roles:
Roles allow you to define different paths between tables. For example, you might
have a 'Manager' role and an 'Employee' role in an Employee table. Each role
defines a different path through the table, allowing for multiple relationships
between the same tables.
Utilizing DAX Functions:
Suppose you have a Date table and a Sales table. You might have one active
relationship between the Date table and the Sales table based on the Order Date
column. Additionally, you might have an inactive relationship between the Date
table and the Sales table based on the Ship Date column. This setup allows you to
analyze sales data based on both order date and ship date independently.
By leveraging multiple relationships involving the same table, you can handle
complex analysis scenarios within Power BI, enabling you to perform detailed and
nuanced analysis of your data.
Data view: In Power BI Desktop, switch to the "Data" view by clicking on the "Data"
icon on the left side of the window.
Select Table: Select the table to which you want to add the calculated column.
Modeling Tab: Click on the "Modeling" tab at the top of the Power BI Desktop
window.
New Column: In the Modeling tab, click on the "New Column" button in the "Tables"
group.
Enter Formula: In the formula bar that appears, enter the DAX expression for your
calculated column. This expression can be a combination of DAX functions,
constants, and references to other columns.
Press Enter: After entering the formula, press Enter to create the calculated
column.
Name the Column: Give a name to your calculated column by typing it directly into
the column header.
Data Refresh: Once you've created the calculated column, you'll need to refresh
your data model to see the changes reflected in your reports.
Calculated columns are particularly useful for performing calculations that involve
simple arithmetic operations, string manipulations, logical comparisons, or date
calculations. They can also be used to derive new information from existing data,
such as categorizing data, creating flags, or generating unique identifiers.
Type of Data: Calculated columns are static and stored in the data model. They
become part of the table in which they are created.
Calculation Scope: Calculated columns are calculated row-by-row during the data
loading process, meaning they are calculated once and stored in the data model.
They are static and do not change unless the underlying data changes.
Use Cases: Calculated columns are typically used for creating new columns based on
existing data within the same row or for performing calculations that need to be
performed at the row level. For example, you might create a calculated column to
concatenate two text columns, calculate profit margin, or categorize data.
Measures:
Type of Data: Measures are dynamic and calculated at query time. They are not
stored in the data model; instead, they are calculated on-the-fly based on the data
being queried.
Calculation Scope: Measures are calculated based on the context of the report or
visualization in which they are used. They can react dynamically to user
interactions such as filtering, slicing, and drilling down.
Use Cases: Measures are typically used for performing aggregations, calculations
across multiple rows or tables, or calculations that need to respond dynamically to
user interactions. For example, you might create measures to calculate total sales,
average revenue per customer, or year-to-date sales.
Key Differences:
Storage: Calculated columns are stored in the data model and consume memory, while
measures are calculated at query time and do not occupy storage space.
Scope: Calculated columns operate at the row level and are static, while measures
operate at the aggregated level and are dynamic.
In summary, calculated columns are used for static calculations at the row level,
while measures are used for dynamic aggregations and calculations at the aggregated
level that respond to user interactions within reports. Both are essential
components of Power BI and serve different purposes in data analysis and reporting.
Concatenating Text Columns: If you have multiple text columns and you need to
combine them into a single column, you can use a calculated column to concatenate
the text values.
Performing Arithmetic Operations: Calculated columns can be used to perform basic
arithmetic operations such as addition, subtraction, multiplication, and division
on numeric columns.
Calculating Ratios and Percentages: You can use calculated columns to calculate
ratios and percentages based on existing numeric columns. For example, you might
calculate a profit margin percentage based on sales and cost data.
Categorizing Data: If you need to categorize your data based on certain conditions,
you can use calculated columns to create flags or categories based on logical
expressions.
Performing Data Quality Checks: Calculated columns can be used to perform data
quality checks and flag records that do not meet certain criteria. For example, you
might create a calculated column to flag outliers or missing values.
Deriving New Attributes: If you need to derive new attributes from existing data,
such as extracting the domain from an email address or extracting the first name
from a full name, you can use calculated columns.
It's important to note that calculated columns are computed during data loading and
are stored in the data model, which can increase memory usage. Therefore, you
should use calculated columns judiciously and consider factors such as performance
and scalability when deciding whether to use them in your Power BI reports.
Sum of Sales:
Calculates the percentage of each sales amount relative to the total sales.
scss
Copy code
% of Total Sales = DIVIDE(SUM(Sales[Amount]), CALCULATE(SUM(Sales[Amount]),
ALL(Sales)))
Sales Growth:
Calculates the percentage of customers who have not made a purchase in the last 6
months.
scss
Copy code
Churn Rate = DIVIDE(CALCULATE(COUNTROWS(Customer), FILTER(Customer, [Last Purchase
Date] < TODAY() - 180)), COUNTROWS(Customer))
These are just a few examples of DAX expressions that you can use in Power BI to
perform calculations, aggregations, filtering, and other data analysis tasks. DAX
is a powerful language with many functions and capabilities, so you can customize
these expressions to suit your specific requirements and analysis needs.
DAX
Copy code
YTD Sales = TOTALYTD(SUM(Sales[Amount]), 'Date'[Date])
Explanation:
SUM(Sales[Amount]): This part of the expression calculates the total sales amount
from the Sales table. It sums up the values in the Amount column to get the total
sales.
TOTALYTD: This is a DAX function that calculates a cumulative total over time
(year-to-date, quarter-to-date, month-to-date, etc.). In this case, TOTALYTD
calculates the cumulative total of sales from the beginning of the year up to the
current date.
When you use the YTD Sales measure in your Power BI report, it will dynamically
calculate the year-to-date sales amount based on the current date. This means that
as you interact with your report (e.g., filter by different dates), the YTD sales
amount will adjust accordingly to reflect the sales from the beginning of the year
up to the selected date.
You can use the YTD sales measure in visualizations, such as line charts or tables,
to analyze the trend of sales performance over time and compare it to previous
years or periods. It provides valuable insights into how sales are progressing
throughout the year and helps identify patterns or trends in sales data.
DAX
Copy code
Total Revenue =
VAR CurrentYearRevenue = CALCULATE(SUM(Sales[Amount]), 'Date'[Year] =
YEAR(TODAY()))
VAR PreviousYearRevenue = CALCULATE(SUM(Sales[Amount]), 'Date'[Year] =
YEAR(TODAY()) - 1)
RETURN CurrentYearRevenue + PreviousYearRevenue
Explanation:
VAR: This keyword is used to declare a variable. It allows you to define a name for
the variable and specify its value within the same DAX expression.
CurrentYearRevenue: This variable calculates the total revenue for the current
year. It uses the CALCULATE function to apply a filter on the Sales table based on
the year from the Date table that matches the current year (YEAR(TODAY())).
PreviousYearRevenue: This variable calculates the total revenue for the previous
year. It follows a similar approach to CurrentYearRevenue but filters the data for
the previous year (YEAR(TODAY()) - 1).
RETURN: This keyword is used to return the final result of the DAX expression. In
this example, it returns the sum of the current year revenue and previous year
revenue.
Readability: Variables allow you to break down complex expressions into smaller,
more manageable parts, making your DAX code easier to understand and maintain.
Reuse: Variables allow you to reuse values or expressions within the same DAX
expression, reducing redundancy and promoting consistency in your calculations.
Overall, variables are a powerful feature in Power BI that can enhance the
flexibility, performance, and readability of your DAX code, particularly in
scenarios where you need to perform complex calculations or manipulate data within
your data model.
DAX
Copy code
CurrentYearSalesYTD =
VAR CurrentYearStartDate = DATE(YEAR(TODAY()), 1, 1)
VAR CurrentYearEndDate = TODAY()
RETURN
CALCULATE(
SUM(Sales[Amount]),
FILTER(
ALL('Date'),
'Date'[Date] >= CurrentYearStartDate && 'Date'[Date] <=
CurrentYearEndDate
)
)
PreviousYearSalesYTD =
VAR PreviousYearStartDate = DATE(YEAR(TODAY()) - 1, 1, 1)
VAR PreviousYearEndDate = DATE(YEAR(TODAY()) - 1, MONTH(TODAY()), DAY(TODAY()))
RETURN
CALCULATE(
SUM(Sales[Amount]),
FILTER(
ALL('Date'),
'Date'[Date] >= PreviousYearStartDate && 'Date'[Date] <=
PreviousYearEndDate
)
)
CurrentYearSalesYTD: This measure calculates the year-to-date sales for the current
year. It uses the CALCULATE function to sum the sales amount, applying a filter to
include only dates from the beginning of the current year up to the current date.
PreviousYearSalesYTD: This measure calculates the year-to-date sales for the
previous year. Similar to CurrentYearSalesYTD, it sums the sales amount, but it
filters data for the previous year's YTD period.
You can use the SalesComparisonYTD measure in your Power BI reports to visualize
the year-over-year change in sales year-to-date. For example, you could create a
card visualization to display the difference in sales between the current year and
the previous year.
Drillthrough filters allow you to pass filters from one report page to another when
drilling through from a visual.
You can specify which fields to pass as filters and how they should be filtered
when users drill through from one page to another.
Drillthrough filters help users navigate through related data and perform detailed
analysis.
Filter Pane Filters:
The filter pane contains filters that are applied globally to the entire report.
You can add filters to the filter pane to control which data is included in all
visualizations on all pages of the report.
Filter pane filters provide a centralized location for managing filters and are
useful for applying common filters across the entire report.
Cross-Report Filters:
Cross-report filters allow you to pass filters from one report to another.
You can configure cross-report filters to send filter context from one report to
another when users navigate between reports.
Cross-report filters enable seamless integration between multiple reports and help
maintain consistency in filtering across different reports.
These are the main types of filters in Power BI that you can use to control which
data is included in your visualizations and calculations, allowing you to analyze
and present your data effectively.
Slicers:
Visual Interface: Slicers are interactive visual controls that provide a user-
friendly way to filter data. They typically appear as a list of values or a range
of values that users can select from.
Visual Level Filtering: Slicers are applied at the visual level, meaning they
affect only the data displayed in the visualization(s) where they are placed. They
do not impact other visualizations on the report canvas.
User-Friendly: Slicers are intuitive and user-friendly, making it easy for users to
filter data interactively without needing to understand complex filtering logic.
Filters:
Behind the Scenes: Filters are applied behind the scenes and are not visible to
users. They are typically created using DAX (Data Analysis Expressions) or through
the Power BI interface without being displayed as a visual control.
Scope: Filters can be applied at different levels, including visual level, page
level, report level, or even at the data model level. They can control which data
is displayed in specific visualizations, across entire pages or reports, or even
globally across the entire data model.
Complex Filtering Logic: Filters can be more complex than slicers, allowing you to
define advanced filtering logic using DAX expressions. You can filter data based on
conditions, calculations, or relationships between tables.
To create a pivot chart, start by adding a new visualization to your report canvas.
From the Visualizations pane, select the "Matrix" visualization icon to add a pivot
chart to your report canvas.
Configure Rows and Columns:
Once the pivot chart is added to the canvas, you need to define which fields will
be used for rows and columns.
Drag and drop the fields from your dataset into the "Rows" and "Columns" well in
the Fields pane to define the row and column headers of the pivot chart.
Add Values:
Next, you can add fields to the "Values" well to calculate aggregate values for
each intersection of rows and columns.
Drag and drop the fields from your dataset into the "Values" well to define the
aggregate functions (e.g., sum, count, average) to be applied to each cell in the
pivot chart.
Format and Customize:
You can format and customize the appearance of the pivot chart using the formatting
options available in the Format pane.
Customize the font size, color, borders, and other visual properties to make the
pivot chart more visually appealing and informative.
Interact and Analyze:
Once the pivot chart is configured, you can interact with it by selecting different
fields or values.
You can use slicers, filters, or drill-down functionality to dynamically filter and
explore the data displayed in the pivot chart.
Additional Features: