Docsity

BUSINESS ANALYTICS TOTAL, Appunti di Analisi Dei Dati

Toggle sidebar
bg1
FIRST LESSON
Each corporation has a network--> domain.
A server is a shared machine to which every comuputer of the firm is connected to. Each worker has
access to it with his own account. Each worker can exercise some command on the data at the same time.
These commands are part of the SQL--> Structured query (richiesta) language.
We also have the “gestionale” or ERP ENTERPRISE RESOURCE PLANNING, which is a very expensive
piece of equipment. This piece of software is responsible for translating what we want to do with the
database in simple ways.
Database--> collection of tables who have a very specific layout, for eg collection of columns. The database
needs to be managed (database management system= DBMS). We need a language to translate the
tables. an example of DBMS is SQL.
If a computer is external to the company there are sever that protect the corporation. If you are a user
outside of the corporation (who is not listed in the list of users who have access to the server) then you
cannot connect to the server. This is important because a database is a sophisticated system where users
see multiple tables and modify them. Any system if it exists can be broken, but there are also sophisticated
systems of defence.
Tables can be:
-
DIMENSIONS--> list of entities. Ex: customer, product, plant. We look at the data from the fact table
from a different prospective/dimension, by focusing on one entity (pivot table). Usually dimension have
many columns, each describing a quality of the entity, and fewer rows, as there are no repetition of the
same specific entity (on the contrary in the sales table one customer can do multiple orders.)
-
Primary key--> column that does not have any duplicates nor blank cells.
-
Foreign key-->counterpart of the primary key in the original table: links two tables.
-
ERP can be used for storage not analysis
Rigid and stiff--> they need to comply with laws
-
If we analyse data through an excel file reliability goes down--> everyone can access the file and change
data
BUSINESS INTELLIGENCE (BI)
Science of how to turn data into information. Data is tables and we can't use tables to make decisions
cause they are too large. From tables we need to generate reports which will help us make informed
decisions.
BI tells us what things are, not WHY. To know cause and effect we need to use statistics, forecasts,
regressions…
We wont' focus on DAX but on POWER QUERY.
SECOND LESSON
SERVERS can be:
On premises--> the server is physically on the corporation facility (most used)
-
On cloud--> remote. Ex. Amazon, microsoft ecc.
-
In a single server we can have one ore more databases, which we call storage databases, they reason in
terms of rows. Thus they are good to storage data, not aggregate it.
BUSINESS ANALYTICS
martedì 31 dicembre 2024
10:21
theory Page 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Anteprima parziale del testo

Scarica BUSINESS ANALYTICS TOTAL e più Appunti in PDF di Analisi Dei Dati solo su Docsity!

FIRST LESSON

Each corporation has a network--> domain.

A server is a shared machine to which every comuputer of the firm is connected to. Each worker has

access to it with his own account. Each worker can exercise some command on the data at the same time.

These commands are part of the SQL--> Structured query (richiesta) language.

We also have the “gestionale” or ERP ENTERPRISE RESOURCE PLANNING, which is a very expensive

piece of equipment. This piece of software is responsible for translating what we want to do with the

database in simple ways.

Database--> collection of tables who have a very specific layout, for eg collection of columns. The database

needs to be managed (database management system= DBMS). We need a language to translate the

tables. an example of DBMS is SQL.

If a computer is external to the company there are sever that protect the corporation. If you are a user

outside of the corporation (who is not listed in the list of users who have access to the server) then you

cannot connect to the server. This is important because a database is a sophisticated system where users

see multiple tables and modify them. Any system if it exists can be broken, but there are also sophisticated

systems of defence.

Tables can be:

FACT TABLES--> list of events. It contains the things we want to describe and it is OUT OF these

tables that we make our calculations. Usually facts tables have fewer columns as not all

characteristics are included, just a key identifier that is linked to a DIMENSION. Ex: sales tables-

event: transaction

DIMENSIONS--> list of entities. Ex: customer, product, plant. We look at the data from the fact table

from a different prospective/dimension, by focusing on one entity (pivot table). Usually dimension have

many columns, each describing a quality of the entity, and fewer rows, as there are no repetition of the

same specific entity (on the contrary in the sales table one customer can do multiple orders.)

  • Primary key--> column that does not have any duplicates nor blank cells.
  • Foreign key-->counterpart of the primary key in the original table: links two tables.

ERP can be used for storage not analysis

  • Rigid and stiff--> they need to comply with laws

If we analyse data through an excel file reliability goes down--> everyone can access the file and change

data

BUSINESS INTELLIGENCE (BI)

Science of how to turn data into information. Data is tables and we can't use tables to make decisions

cause they are too large. From tables we need to generate reports which will help us make informed

decisions.

BI tells us what things are, not WHY. To know cause and effect we need to use statistics, forecasts,

regressions…

We wont' focus on DAX but on POWER QUERY.

SECOND LESSON

SERVERS can be:

  • On premises--> the server is physically on the corporation facility (most used)
  • On cloud--> remote. Ex. Amazon, microsoft ecc.

In a single server we can have one ore more databases, which we call storage databases, they reason in

terms of rows. Thus they are good to storage data, not aggregate it.

BUSINESS ANALYTICS

martedì 31 dicembre 2024 10:

ERP(enterprise resource planning) softwares connect to the storage database and enables us to aggregate

data. Main tasks:

  • Insert
  • Update
  • drop

Excel is not a database, we shouldn't use it to store data.--> it's a spread sheet.

If we want to ANALYSE the data and not simply insert/drop form the database, we cannot use ERP. We

should use use self-service BI softwares.

We should never extract manually data from excel or connect data to excel, it is inefficient because by

connecting it to excel we could corrupt and spoil the data, so it is better to connect BI to databases as a

source.

However, we cannot use storage databases as sources, we need analysis databases , called columnar

(keep data in columns).

DATA WAREHOUSE --> storage database which is fed by the data in the ERP storage database, which we

use as source.

For analysis we want to take data from storage databases and put it into the analysis database. The problem

is that data in storage databases is NORMALIZED--> nested architecture with lots of fact tables and

dimensions to avoid repeating the same information many times and maximise efficiency (least amount of

memory used).

This structure is good for storage but not to analyze: I want less tables.

To avoid this architecture in data analysis, we use data warehouses--> storage databases from different

databases in which data are denormalized:

  • less efficient but easier to analyze, as there are less table
  • Harmonize data --> Make data in original different databases comparable and consistent (same unit)

If new data is added to storage databses, the data warehouse must be refreshed to be syncronized with the

ERP databases.

(BI) Business intellingence has 4 steps:

ETL --> extract, tranform, load in another database. Get tables out of the warehouse (refresh: realign

data used for analysis to the warehouse), trasform and load in analysis database.

  1. Data modelling --> connect tables through relationships (measures, calc columns, data security)
  2. Data visualization --> dashborads, histograms ecc.
  3. Sharing --> with the corporation.

In power BI you cannot insert/update/drop, you can just analyze.

After BI we have ANALYTICS(inference), which tells is how things might be. It tries to predict what will

happen. BI tells us how things really are.

SQL-->Doing analytics and reporting with this database management system (SQL server) is very difficult

because it is not made for this purpose. This works well only for inserting deleting and updating, so for the

ERP.

Instead we can connect Power BI to the SQL server.

We can connect to SQL in two ways:

  • Import
  • Direct to query

If you connect through IMPORT, you need to refreshh everytime the database changes.

IMPORT--> we are connected to the data warehouse and we loaded the data during the ETL phase as a

COPY (the data used is IN tabular). If somethings changes in the warehouses i need to refresh.

Disadvantages--> i need to refresh. However, I rarely need an immediate update as soon as

changes happen.

Advantages--> speed. As the data is directly in tabular (PBI)

User experience is much better.

BI PROCESS--> Connect to datawarehouse or multiple databases, here we choose the tables we need

ETL--> extract, tranform, load. We can REMOVE, RENAME A COLUM, CREATE A COLUMN, OR

GROUP DATA, MERGE TABLES (working on the copy). We will use power query (still storage

database, thus works on rows).

DATA MODELING--> the cleaned tables will be imported in the analysis database, which is tabular and

understands DAX, in order to model the data: connect tables.

3. DATA VISUALIZATION--> will create a dax query to populate the visuals. Called power view.

SHARING--> you share your reports for the whole corporation to see. Use power BI cloud to put the file

in production.

Difference between tabular and sequel

  • Tabular stores data one column and a time--> each column is indipendent

Refresh of tables used for the analysis purpose.

ETL

To connect to data (not a flat file) we have four different options:

Importing --> make a copy of the data and physically store this data into the analysis database (tabular).

This is the best option, its only limit is that the data you load in tabular is loaded in the RAM (random

access memory), which is faster than the hard disk. However, whatever is stored in RAM is lost when

the computer is turned off, so it must be reloaded to the disk. Obviously, the RAM must be big enough to

fit the data. (best option)

With excel we can only import.

Direct query--> data connected to an external source

a. To a storage database

b. To an analysis database

  1. Live--> data will not be stored in our power BI and it will be connected to an external source.

Importing --> excel file dataset 01

We need fact tables and dimensions SEPARATED (star schema)

  • SALES--> fact table

Dimension--> prospective through which we want to analyse sales. Ex. Calendar, customer, product,

territory

If we create our own dimensions there is a question we will never be able to answer--> are there customers to

which we sold nothing? Because we inly see customers who placed an order. This meand we loose some

power.

When we connect to the excel file we can select which tables to include:

Its easier to include new columns later than to delete them later.

When we click on trasform data (to further clean it) the data is not imported yet, but it is stored in a temporary

database called mesh engine (power query).

POWER QUERY--> to transform data

  • We have one query for each table we selected

For each query we can see on the right, a set of steps—> transformation steps, in reality they are

connection steps (ETL is also extraction, not only transformation).

Source--> address of the file. Same source for all tables. ○

○ Navigation--> table selection. In this case we have 5 different navigation.

○ Promoted headers--> as we are using excel, the first row is the name of the column

○ Changed type--> decides a single data type for each column

Anything you do in power query is documented--> creates a new step/delete a step

Example--> select only some columns--> select CHOOSE COLUMNS, this will show all columns we have and

we can select only those we actually want. This will ad an additional step removed other columns step.

Once we are done with our changes we can load them to tabular--> CLOSE&APPLY.

We should always avoid intermediate steps as

it will affect consequent steps.

In Power BI the data can be showns:

  • In Tables
  • As model (where we create connections)

This database doesn’t work on rows, so the row number concept doesn’t mean anything and this database

works only on columns so in reality it is storing this table into separate columns.

We can always go back to power query to change the data

If we need a column we can ALWAYS add it later. Removing a column on the other hand can create

problems.

Thus we need to go back to power query to change some steps--> click on TRANSFORM DATA

In calendar i choose datecolumn not datekey (code of digits not understandable)

Then I can close&apply again. These changes won't create any errors.

If we click on refresh, power query will reconnect to the source and reload all data.

What happens if I change the name of the excel file? Power query won't find the source anymore.

However, in tabular even if the refresh will fail, the old data has still been memorized, so we can keep on

working. In this case we can:

  • The name of the file must change--> data source setting--> change source and edit the name

Change the file name to the original name and refresh

If I want to add tables I didn't select at the beginning i need to go back to the existing source--> RECENT

SOURCES. This way we can select the additional tables we want (DO NOT reselect the tables we already

imported as they will load twice).

In the modelling area we create the connections between the dimensions:

We create a one-to-many connection.

Example of normalized data--> one table for subcategory and one for category

We click on the green gear to

change the selection of columns.

We can also change their names.

In this case I wanted to add productcategory and

prosuctsubcategory.

Tranform data--> clean the data with what I need--> close&apply

First let's visualize the data. If we want to see sales by product we can create a matrix.

What I want to avoid is having so many different tables to pick information from--> i want sub and category in

the product table.

We should go back to the ETL phase.

In the modeling part--> tranasform data--> first we want to merge the cateogry and subcategory table.

We go on the subcategory table and click on merge queries.

Then I deselect the category key:

Now I can do the same between product and subcategory table.

Click on the product table--> merge queries--> select subcategory table and the key to connect the two.

Now I have denormalized the data.

I cannot kill the subcategory and category tables, cause I need them for the merge. However, I dont wanna

load them into tabular.

Now I can close&apply and I'll see that those two tables have been removed. I have a STAR SCHEMA.

  • In rows we put the english product name

We need to create a new measure for sales--> click on the three dots--> new

measure--> sales = sum (sales (salesamount)) --> add this to the values section

Now for each product I can see the amount of sales, however this is very

detailed.

What if I want to see things more grouped? I can go to the subcategory level.

In rows, instead of english product name we can put english subcategory

name.

If I want even less details, I can take the category name.

As the second table I select product

category. then I click on the two columns I

want to use to connect the tables

(productcategorykey)

Do not use original column name as prefix

I enable the load for both tables.

DENORMALIZATION

If I go back to the matrix I have created before It will give me an error:

However, englishproductcategoryname is now in the product table, so I can take it from there.

Now we are back to what we had before but with a denormalized structure.

SIZE OF DATA

When we load the data into tabular we are memorizing it into our RAM, meaning that we need to have

enough space to load everything.

One way to reduce the size of data is cleaning the columns we don't need (as we did), however sometimes

that is not enough. We have three solutions:

  1. Reduce the extension in terms of time --> only last 6 months/two years/10 years.
  2. Keep the entirity of the time period but we reduce the granularity --> less detailed in the information
  3. We reduce both time and granularity

If we cannot reduce data enough, or the reduction would make the data useless we need DIRECT QUERY.

In this case I am not loading it into tabular, so it can be as big as it needs to be. However, this decreases

performance. Why?

With direct query I only load the metadata (column names), meaning that in case I want to create a graph It

needs to go all the way back to the database--> This takes time. Direct query is the last option, in addition to

this it only works with databases not with excel files.

How can we reduce the data size?

Reduce time span--> we want to restrict the bigger tables (ex: sales, transaction - customer table

should be smaller cause we hope we have multiple purchases per customer)--> transform data

This added another step on the left, I can always change the date by clicking on the gear.

This row doesn't exist anymore, cause I don't have that

table.

In this case we want to keep

only the sales after the first of

january 2003.

To do this we need to calculate a column with only month and year. I open power query, and in the sales

table I can add a COLUMN FROM EXAMPLES.

Now we have the year and the month and I can group by:

This way the order dat will disappear.

Now we can try something different:

This technique called grouping and aggregating is just a way to avoid having too much data. We can now

close&apply.

However, if we look into the model view we can see that we lost the connection between product and

sales,because we decided to loose the product info. We also lost the connection between calendar and

sales, because we decided to loose the key that connected the two (order date). To solve this problem we

should create a many-to-many relationship.

Still in TABULAR I can concatenate the column of year and month--> add new column both in sales table

and in calendar in order to be able to connect the two.

I write down 11, as it is the month in the

first row and it will automatically

understand what I want to extract.

I can do the same for the year.

Instead of grouping, create the month and the year column, and the

grouping again, we create the two columns before and groupo only

once.

I can just drag inserted motnh and inserted year above the frist

goruping. Then I kill the second one and modify the first by adding

what we did in the second one.

We can now connect the two tables. However, as none of the two is a primary key, when we create the

relationship it will be many-to-many.

We want to change this format of the yearmonth:

UNPIVOTING

Dowload the file on virtuale 2024- 10 - 01 unipivot data.

This process is called UNPIVOTING.

I connect PowerBI to the excel file--> select the table--> transform data.

The region column is good, it does not have to be unpivoted. I can do this process in two ways:

  • Select the columns I need to unpivot--> transform--> unpivot columns
  • Select the column I DO NOT need to unpivot (region)--> transform--> unpivot other columns

If I go back to the excel file and change the data (the file must be saved on your computer), I can just go to

powerBI and refresh the unpivot table and the new data will appear.

UNION/APPENDING

Suppose we have data in different table that we want to put together. (ex: table for sales 2020, table for sales

2021, table for sales 2022 ).

We need to duplicate the query of the sales table

I need to do this in both

calendar and sales.

Example of table which is good to insert data, but not to analyze it.

Because it mixes time and datatype--> FCAST 2024

I can rearaange the table in Power BI.

This is what I get. Now I want to isolate

the year.

I select the attribute column--> split

column--> by delimiter

This is the final result, now I can

click on close and apply.

In the copy we remove all steps after removed other columns

FIFTH LESSON

Now we start to deal with multiple fact tables.

We connect to dataset 01, we select sales (fact) + calendar, customer, product, territory (dimensions).

Suppose we want to consider both sales and customer service (infoservice - phonecalls ).

Why? Suppose we want to compute a margin, we not only need the cost of good sold but also the cost of

additional services.

We could also want to pair with budget. In that case we would have an additional problem of granularity, as

budget does not have the same level of detail. The table of budget is more rough than the table of sales as

it is constructed the year before and it does not predict the entire set of transaction.

Today we use two fact tables with the same granularity--> infoservice

(The only thing we do not have in infoservice is territory, because in this case the concept of territory does

not apply as it concerns phonecalls, not sales.)

Now we can clean the tables in power query. In infoservice we keep everything. In the sales table we only

keep the key to connect to the dimensions + salesamount, quantity, price.

Note: we do not have to keep a key to connect to infoservice because that is another fact table, not

dimension.

In salesterritoty I delete the alternatekey. I clean also the other tables.

Now we can close & apply to tabular.

The relationships were created in automatic

Sales was connected to customer, territory and product. Not calendar as PowerBI did not find two

columns with the same name.

Calendar does not have an intrinsic business meaning. It is us that decide whether to connect to

orderdate, shippingdate, receiving date ecc. in this cause we use the business meaning of order date.

Now sales is connected to all dimensions.

We will go back to infoservice later.

We create our first visual: matrix (pivot table). Let's say we want to see the revenue per color product.

  • Row --> color
  • Value--> new measure in sales:

Now we want to include the time these orders refer to. Two approaches:

  • Add calendar year to rows
  • Add a slicer --> I add calendaryear to the fields. To change how it looks:

On the bottom I have the two fact

tables, on the top we have the

dimensions.

This is not a pure star schema,

cause that would only include one

fact table.

Now If I click on a year the other matrix will only show the orders from that year (not invoice!)

To keep two years--> ctrl.

In the selection you can choose--> multiple select or single select

Note: you only filter through dimensions

Assume we want to see order quanity through continet--> bar chart (clustered column chart).

  • X axis--> territory country
  • Y axis--> new measure to see the order quantity

To obtain this

All visuals filter each other. If I click on united states in the bar chart the numbers in the matrix will also

change to orders only related to the USA. Same if I click on black in the matrix.

Now we want to calculate MARGINS (revenues - costs).

We need to find information regarding costs--> open power query and include the column totalproductcost

What if we want to calculcate the weighted average price:

--> total revenue / total quantity sold--> we already have these two measures (order amount and order

quantity)--> we create a new measure using these existing two

Now we want to create a measure to calculate the margin, having the salesamount and the

totalproductcost.

I already have the sum of sales amount called orderamount, but I need to compute the sum of the

productcost.

Now we can create a margin amount measure:

Now we can create a time visual--> line chart

  • Y axis--> order amount and margin amount
  • X axis--> english month name

Note: for some reason the graph was sorted by

the measure orderamount, we changed that

Another problem was that the month were now

displayed in alphabetical order. To change that we

sorted the column by month number of year (sort

a column through another one)

Finally I click on sort axis ascending.

Now I want to compute the margin that considers both COGS and cost of calls.

I don't explicitely have a cost of calls, we can assume that each minute has a cost.

If we assume 1€ per minute (60€ per hour), the measure would simply be equal to the call minutes.

If we assume 1 hour is paid 100€, first divide the call minutes to find the number of hours, then we multiply

by 100€.

Now we can create the measure for the total margin amount: margin amount on godds sold - call cost

The matrix will look like this

What is the margin in percent of sales if we consider also the calls? How many percentage points we loose

due to that department? (how much it costs us)

If I don't consider tha call cost, the margin is very stable.

If we consider the costs of call service:

If we compute the difference between the two margins we find the percentage points lost due to the call

service:

I can also see how the margins changed through time

(I can just copy and paste the graph from another

page)

(We had duplicated page 1)

SIXTH LESSON

How to connect to SQL servers.

Now we launch SQL management studio 20.2, to work with a server.

  • Server name: FSI-SQL
  • Authentication--> SQL server athentication
  • Login--> studenteBA
  • Password--> studenteBA
  • Encryption--> optional + trust server certificate

Now we can connect.

In this server instance many databases are loaded. We want to try to run a query against one of these

databases.

The database on which we want to run the query is contosoForTeaching.

Now we can open PowerBI. Now as a source we can select SQL server.

(this works only on unibo computers for security purposes, thus from now on I'm still working with the excel

file database 01)

MULTIPLE FACT TABLES - different granularity

We want to work with sales and budget. Usually budget has ffar less details.

  • Fact tables--> sales and budget
  • Dimensions--> customer, calendar, product, territory

In this case I don't want to clean tables so I load them directly.

What is the level of granularity of budget table?

  • Time--> month level (not daily as in sales)
  • Territory--> we just have region name, we don't have the key
  • Product--> we only have subcategories, not budget for specific products
  • Customer--> no customer detail at all

Let's try to create relationships.

Then we can click on newQuery, which means making a request on

the sevrer to know something.

Example--> I want to know the content from the customer table.

Now we can click on execute.

Same credentials

Now we should try with the other dimensions.

If we select product--> color, we can see that the budget doesn't change because the two tables are

not connected.

However, we can see that in the budget table we have the column subcategory. Thus, we could bring in the

subcategory table (we didn't include it) and then connect budget to subcategory and subcategory to product.

Recent sources--> include productsubcategory

The productsubcatgeory table should be automatically connected to the product table. Now we need to

decide how to connect it to the budget table.

I can link englsihproductsubcategoryname (subcategory table) to subcategory (budget table).

However, if we go back to the matrix sliced by color, it stil doesn't work. Why? Because color comes from

product not subcategory.

If we try to slice with something coming from the subcategory table, it DOES work.

The maximum level of detail in the budget table is subcategory NOT PRODUCT. This the maximum detail

we can reach.

How can I solve this?

Can I kill the product table? NO, because I need the table to connect subcategory and sales. All I can do is

cancel it so I am not tempted to use it to slice matrices.

I cannot go in more detail than subcategory. However, I can always go in LESS detail. For example slice by

category.

To do it we have to bring in the table--> recent sources--> productcategory

The tables will automatically connect--> now I can slice the matrix.

Remember we always prefer denormalized tables--> kill subcategory and category tables and bring them

into the product table.

To do it we need to open POWER QUERY.

I first go to the subcategory table--> merge queries--> we connect the subcategory to the category table

through the categorykey

To completely denormalize I need to go to the product table and bring in the subcategory and category

name--> we connect product to subcategory through the subcategory key.

I only need the englishproductcategoryname in the subcategory

table.

I no longer need the category table.

We only need these two columns.

Now I can disable both subcategory and category tables. Finally,

close&apply.

Now in the matrix if I select category or subcategory it works. However, if I select color this happens:

To hide the columns--> product table

WHAT DOES MANY TO MANY CONNECTION MEAN?

To explain it we will use the time.

If we look at the budget table we can see that the level of detail for time stops at the month number.

As we can only use one column to connect two tables we concatenate yearmonth in budget.

In order to create the connection we do the same in the calendar/date table

Both in budget and in calendar we do not have a primary keys (months duplicate in both).

If we try to create a connection it gives us the warning that the connection is many to many.

We try to do manually what PowerBI would automatically do in order to fully understand the mecanism.

We need to find a way to fix an interval of time that is at the minimum level possible, so that we can

see sales and budget correctly.

Now we should try to connect the product table to the budget table

through the subcategory key. However, this no longer is a primary

key--> so we create a many to many connection.

We connect englishsubcategoryname to subcategory.

Always from dimension to fact.

This might seem correct, but if we had the budget for each

color it does not add to 29991136.

I have multiple budgets in each colors.

I need to hide any column below the level of the

subcategory.

We have no budget below subcategory.

We select the first one (class), then by clicking on shift we click on

the last one. This will select all of them.

Then by clicking on ctrl we deselect category and subcategory.

Now by clicking on the eye all columns exept those two will be

hidden.

Those two are the only column we can actually use.