Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

PowerBI

18 November 2020 16:32

Course https://www.udemy.com/course/mspowerbi/learn/lecture/20493818#overview
Material https://www.superdatascience.com/pages/powerbi

Index
Section 1
• Connect to csv file and load data into PowerBI
• Drill down
• To add color by category
• Add a new column into dataset
• Adding Labels to chart
• Add title
• Change axis labels
• Set data type for column
• Visualize time series data
• Aggregation and granularity
• Convert a line chart into an area chart
• Filters and slicers

Section 4
• Create relationship between two tables
• Types of joins
• Joins with duplicate values
• Joining on multiple fields
• Creating a map with hierarchies, lat and long
• Calculated columns vs calculated measures
• Creating a scatter plot
• Combing charts, filters and slices
• Adding a doughnut chart

Section 5 Creating an interactive business intelligence report


• Mapping how to set geographical roles
• Create table calculations
• Creating bins and distributions
• Create a treemap
• Creating a dashboard

Section 6 : Leveraging custom visuals


• Install a custom visuals for power bi

Section 1

Connect to csv file and load data into PowerBI


• Getdata > CSV

Books Page 1
• Getdata > CSV

• Browse and select file


• Will get a preview

• Click transform data to edit

Books Page 2

• Check your data types

• You will now see your fields in the right hand corner

Books Page 3

• You can always click on the data tab on the left to change the data type of the dataset if
required
• 2 other tabs on the right are: Report and Relationship
• You can also access other types of data like SQL, XML, Json and many other types of data

Navigation Bar

• Home:
○ Refresh: Refresh the data

• Insert:
○ New Page: to insert a new page, you can also do that from the tabs on the bottom or
delete page from there

• Modelling: Options to optimize relationships

Books Page 4

• On the right you can see options for visualizations


• Also have options for: Fields and Format

Visualizations
• Drag two columns onto the plain white space.
• By default they will create a table visualization

• You can convert this into other types of visuals like barchart from the options available on the
right

Books Page 5

• Also have many other types like area chart, pie/doughnut chart, waterfall chart etc
• Ctrl + S- save
• Drill down
• Can drill down into sub categories in your data

• Data > Drill down or press down arrow on the chart


• Click on the chart to drill down to qtr> month>date

Books Page 6

• Click up arrow to drill up

• If we look at option switch to next level from year it goes down to quarter
• But here it shows and arranges the data only basis the level currently specified disregards the
higher levels
• So this is an aggregate of all Q1 in 1st Q2 in second etc, but could be in the wrong order as at
this level disregarding the year value ( in this example 2014 had Q3, Q4 data and 2015 had
Q1,Q2 data)

• Useful for categorical data


• So in case we don’t want that to happen select expand next level instead of show next level

Books Page 7

• Can also pick sort by option

• To see data as table

• Adding colors
• Requirement: Show num of units sold by all the representatives and the region they belong to.
The Rep will be in the x-axis as bar chart and the colours of the bars will represent the region
they belong to
• Step 1: Plot a bar chart with Units and rep

Books Page 8

• Step 2: Add region to x-axis creating an artificial hierarchy

• So can now drill down to get region-rep

• NOTE: Sorting here depends on the order in which you added column to the axis option in
visualization tab
• So if you dragged Region first to will sort by region if rep it will sort by rep to change the order
clear the field and add in the order you want to sort
• To add color by category
• Drag category you want to color code into the Legend option in visualization tab

Books Page 9

• To change go to format> data colors

• This chart is showing total number of units sold but we need to find out the $ value of total
sales from each rep
• Add a new column into dataset
• Fields > right click > new column

Books Page 10

• Specify column formula (auto complete is available)

• Can verify new column is added in the data tab on the left

• Now replace Units with Tot_Sales in values option of visualization tab on the right

• SOLUTION: Whoever has made the max sales in each region will get the bonus
• Hence Mathew, Susan and James will get the bonus

• Adding Labels to chart


• Format> data labels

Books Page 11

• If some don’t fit (like below):

Books Page 12

• Change decimal point

• Inside end is best

Books Page 13

• Add title
• Format > Title

• Change axis labels

• Format> Y axis > Display Units

Books Page 14

• Thousands with 1 decimal unit

• Can also enable title for the axis

• Set data type for column


• Select the column, goto column >Formatting > Format

Books Page 15
• Select the column, goto column >Formatting > Format

• Can also set the decimal limits here

QUIZ

Books Page 16

Exercise: Long-Term Unemployment data US

• Age and gender - categorical data


• Time period and number unemployed
• But this is difficult for humans to read
• People are more used to see the data organized like this:

Books Page 17

• But for programs like power bi that is more difficult to process


• Open the file in power bi

Visualize time series data


• Line chart of unemployed in US long term

• We need to drill down on this time series data and assess if there are any patterns emerging
• If press drill down it just shows specific individual level but does not give a birds eye view
• If we use Switch to next level it becomes a categorial classification at a particular level and
disregards the higher levels

○ Disregards the year completely (higher level disregarded)


○ So here it ceases be a time series analysis and becomes a categorical analysis
○ But sum of this data makes little sense instead analyse the avg value in each quarter to
identify a trend

Books Page 18

○ Avg increases in Q3 but then drops


• Show next level if you click once it moves into the quarter level and this is just the sum of data.
It makes little sense to analyse this. If instead we looked at the average in each quarter we can
get an idea of the trend across all quarters.
• To change from sum to average goto the field unemployment field in Values option and right
click > Average

• We can see now there is a pattern (spike in Q3)

Books Page 19

• There is seasonality. Can observe the same if we drill down into the months as well

• Lets go back to top level and use expand next level instead
• This preserves the hierarchy and shows both the year data as 4 separate points.

• This preserves as a time series

Books Page 20

• Now we can really track how the total unemployment has varied over time
• So this increased the points on your timeline

Aggregation and granularity


• How does power bi do aggregation when we select the period? We have other columns other
than period and unemployment (we have age and gender)
• Power BI knows the level to which to aggregate based on the level of granularity of our
visualization
• We specify the columns, rules and levels and Power BI uses that data to decide how to
aggregate the data and render a visual
• We have numeric column that get aggregate (sum, avg etc) and categorical /timeseries that
specify which level of detail aggregations need to occur

• This graph is technically an aggregation of 2 lines (1 for male other female) but nowhere have
we specified that we need that separate level of detail in the visual
• So to get 2 separate lines take gender and put it into the legend option

Books Page 21

• There are now twice the number of points :


○ We have increased the level of granularity and decreased the aggregation
• If we aggregate by age instead of gender

• Age here is categorical in this set (there are age groups)


• So more granularity means less aggregation
• Granularity: Level of detail
• Aggregation: Converting multiple values into a single value (can be done for both numeric
and categorical data)

Convert a line chart into an area chart


• If you directly convert the chart into an area chart you will get this:

• It is a bit clustered and hard to read so you can convert into a stacked area chart

Books Page 22
• It is a bit clustered and hard to read so you can convert into a stacked area chart

• Top level represents the tonal level of all of the groups


Types of area charts Link
Standard area chart Quant progression over time. Usually a line chart is a more legible
choice

Stacked area chart Part to whole relationship where cumulative total is still relevant
100% stacked area Part to whole relationship of categories where the cumulative total is
chart unimportant
Filters and slicers
• You can select individual elements to highlight them

• What if we wanted same visual but only with the data for male gender
• Can add a filter
• Drag gender field to filter and pick only men

Books Page 23

• There are also options for advanced filtering

• Now we can look at adding a slicer (make a duplicate of the existing sheet so you can always
revert back to it if the new visual doesn’t work)
• Add a slicer as a new visual. Slicers make the filtering of data easier.

• Add gender field to slicer for filtering

Books Page 24

• There is also option to clear all selections


• Can also hold control and select multiple options

• Slicer for period (it is a slider)

• Have other options as well

Books Page 25

QUIZ

Books Page 26

Section 4: Maps, Scatterplots and Interactive BI Reports

Create relationship between two tables


• The Model tab details the connects between the 2 tables

• Click Manage relationships

Books Page 27

• You can press autodetect to find potential relationships when you update the table
• You can also manually create or edit existing relationships

Types of joins

• Types of relationships between tables in a database

• Which employees are also customers?

Books Page 28
• Which employees are also customers?

• Left outer join: No records are discarded from the primary table (here left table) only from the
child table, if no match then those columns are left blank

Books Page 29

• Inner joins and Left join is most commonly used

Joins with duplicate values

Books Page 30

Joining on multiple fields

• Need to link the table with both columns Store and Order # (order # are unique for each store)

Creating a map with hierarchies, lat and long


• Select Map or filled map from Visualizations tab

• Need to create a hierarchy (country, state, city, then lattitude and longitude)
• To do this create hierarchy for country field and add the other fields to this new hierarchy

Books Page 31
• To do this create hierarchy for country field and add the other fields to this new hierarchy

• Rename Geography

• Drag this hierarchy onto the location

• Note if you drill down to the city you will notice it includes some locations in US. That's
because there are cities with the same name in multiple countries and drill down ignores the
data in higher levels.

Books Page 32

• To prevent ambiguity use lat and long


• Dra and drop lat and long fields

• But lat and long are given for each order and at a country level it ends up taking the average

• Instead can use median so it is not affected by outliers

• Putting sales into size of shaded region

Calculated columns vs calculated measures

Books Page 33
Calculated columns vs calculated measures
• We want calculate the profit margin (profit/sales)

• Cal columns are calculated before aggregation and cal measures are done after aggregation
• Cal measures are calculated on the fly/dynamically when you render the visualization unlike
cal columns which are stored in the table
• Create a calculated measure
○ Right click > New measure


○ Remember columns used must be aggregated
○ Put color saturation

○ Set the gradient colors in Format tab > Data Colors

Books Page 34

○ OR if color saturation is not available


○ Format > Data color > fx

○ Set a color scale

○ It is recalculated dynamically for the lower levels as you expand

Creating a scatter plot


• Select visualization Scatter plot
• X axis: sales, y axis: profit

Books Page 35

• Only 1 dot as you have not specified the level of aggregation, for which you will need to
specify some categorical or non numeric variables

• We specify that in fields > details

• But it doesn’t add a lot of value analyzing regionwise instead look at which customers are the
most profitable
• So use customer name as details

• Set color saturation in format tab


• Format > Data color > fx

Books Page 36

• Profit margin can be negative but sales will only be positive


• For customers/product with low profit margin analyze if the products can be either
discontinued or sourced more efficiently. If not try to stop servicing those customers (increase
prices, reduce discounts etc)

Combing charts, filters and slices


• Filters can be specified at a visual level, page level or document level

• Filter out item sold in year 2011


• Drag and drop field > select advanced filtering

Books Page 37
• Drag and drop field > select advanced filtering

• Simpler to use a slicer


• Put both charts on same page and apply slicer
• Copy paste and resize on a new page
• Add a slicer with field order date

• Add another slicer for region

• To make the options in slicer look like control buttons:

○ Format > general > orientation > horizontal

Books Page 38

○ You can also add background or borders to make the buttons more visible
• You can also disable the header for the slicer

• To prevent map from resizing every time settings are changed

• To prevent scatter plot from resizing


○ Set the min and max for x and y axis
○ Format > X axis and Y axis

Books Page 39

Adding a doughnut chart


• For a doughnut chart you need one numeric field and one categorical field

• Arrange into a dashboard

Quiz

Books Page 40

Section 5 Creating an interactive business intelligence report


• Dataset: details about customers at a bank

Books Page 41

• Create a dashboard showing demographics


Mapping how to set geographical roles
• Drag region field and select the chart type as filled map

• Add region to both legend and location

• In case it is still not recognized, select the field and go to column tools > data category > state
or province

• To prevent automatic resizing

Books Page 42
• To prevent automatic resizing

• Show the number of customers in a selected region


○ You cannot add customer id to the legends
○ Instead add a card chart above the map

○ The count of customers will be displayed dynamically based on the region selected

Create table calculations


• For gender

• Select pie chart and fields customer id and gender


• Can customize the format of the chart

• To calculate % of total for the customer ids


• Select new quick measure

Books Page 43

Creating bins and distributions


• Right click on column > new group

• Set bin size

Books Page 44

• You can even display as % of grand total

• Create bins and distribution for balance

Books Page 45

• You can set as % of gt

Create a treemap
• Similar to pie chart

• When you have a lot of different categories a pie chart can get overwhelming and the breakup
is less evident
• Can set to display the % of grand total

Creating a dashboard
• Copy and paste all your charts onto a new sheet

Books Page 46
• Copy and paste all your charts onto a new sheet

• To check dashboard layout on other devices go to view

• You can also add gridlines and snap to grid for easy formatting. Mobile layout option is also
available
• Set intuitive titles

• But if you select a particular category or region there is a overlay


• To control the interactions that happen when you select a chart go to format > edit
interactions

Books Page 47

• You have 3 options for how a chart can react to selection: filter, highlight or none
• If you select filter it will no longer have that underlay of the total data

• Select for each chart and set the filter

Analysing results

Books Page 48

• For England there is a sudden dip in the bank balance is that because people in that income
category prefer banking with competitors
○ It is reasonable to make this type of assumption if you have a lot of data points but if
you have very few customers in this segment then there is a chance that the dip or
deviation is just due to noise

Quiz

Books Page 49

Section 6 : Leveraging custom visuals


• Europe debt crisis

Install a custom visuals for power bi


URL https://appsource.microsoft.com/en-us/marketplace/apps?product=power-bi-
• visuals
• Force directed chart
• Chord chart

Books Page 50

You might also like