Transcript Data mining - Texas Tech University
ISQS 3358, Business Intelligence
Cubism – Measures and Dimensions
Zhangxi Lin Texas Tech University 1
Outline
Where we’ve been Populating fact table Creating a cube with SSIS Measures Types of dimensions Cube design tabs 2
Structure and Components of Business Intelligence
SSMS SSIS SSAS SSRS SAS EG SAS EM 3
Snowflake Schema of the Data Mart
10
Manufacturingfact DimBatch DimMachine
3
DimProduct
5
DimMachineType
2
DimProductSubType
1
DimProductType
4
DimMaterial
9 8
DimPlant DimCountry
7 6
4
Where we’ve been and where we are now
Exercise 1: Getting started Exercise 2: Creating data marts Exercise 3: Creating a cube from a data mart Exercise 4: Populating dimensions of a data mart Exercise 5: Exploring features of ETL data conversion tasks Exercise 6: Loading fact tables
5
What we need to do with the half-done data mart?
Populate DimBatch dimenstion table Populate ManufacturingFact table Build an OLAP cube (we already did this before) Check measures Check dimensions 6
LOADING FACT TABLES
7
Exercise 6: Loading Fact Tables
Project name: MMMFactLoad-lastname Package name: FactLoad.dtsx
◦ ◦ Tasks ◦ Create Inventory Fact table ◦ Load Dim Batch Load Manufacturing Fact Load Inventory Fact Deliverable: email a screenshot of the “green” outcome of the ETL project to [email protected]
8
Inventory Fact Table
Create a Table InventoryFact in database MaxMinManufacturingDM-lastname.
◦ Compound primary key: DateOfInventory, ProductCode, and Material ◦ Define two foreign keys
Column Name
InventoryLevel NumberOnBackorder DateOfInventory ProductCode Material
Data Type
Int Int Datatime Int Varchar(30)
Allow Nulls
No No No No No 9
Data Sources for Loading Fact
For loading DimBatch table and ManufacturingFact table ◦ BatchInfo.CSV
For loading InventortyFact table ◦ OREDB.OrderProcessingSystem.Inventory 10
Control Flow for Loading Facts and the Remaining Dimension Note: to ease debugging, you may use three packages and test them one by one, instead of doing everything in one package 11
Flat File Connection
Data types ◦ BatchNumber, MachinNumber: four-byte signed integer [DT_I4] ◦ ProductCode, NumberProduced, NumberRejected: four-byte signed integer [DT_I4] ◦ TimeStarted, TimeStopped: database timestamp [DT_DBTimeStamp] Only check BatchNumber as the input of Dim Batch All columns are needed for fact tables 12
Load DimBatch Data Flow
13
Load DimBatch Data Flow
Note: Because of duplication in the source file, we may insert An Aggregate item after the Flat File Source item.
14
The Flat File Source
15
Sort Transformation In the Aggregate item, Define “Group-by” BatchNumber.
In Derived column item, Define BatchName From BatchNumber
16
Load Fact Data Flow
17
Derived Columns for the Fact table
18
Expressions for the Derived Columns AcceptedProducts ◦ [NumberProduced] – [NumberRejected] ElapsedTimeForManufacture ◦ DATEDIFF(“mi”, [TimeStarted],[TimeStopped]) DateOfManufacture ◦ (DT_DBTIMESTAMP)SUBSTRING((DT_WSTR,25)[T imeStarted],1,10) This expression converts TimeStarted into a string and selects the first ten characters of that string. This string is then converted back into a date time, without the time portion.
19
OLE DB Destination For loading the fact table
20
Load Inventory Fact
OLE DB Source ◦ OrderProcessingSystem.InventoryFact
OLE DB Destination ◦ MaxMinManufacturingDM-lastname.InventoryFact
No transformation There are two ways to loading the table ◦ Create the table and use ETL to load it ◦ Import directly from the source to the database MaxMinManufacturingDM-lastname 21
Debugging Results
Loading DimBatch Loading ManufacturingFact 22
BUILDING AN OLAP CUBE
23
Three Steps to Create a Cube from Data Sources Defining data source Defining data source view ◦ Add in three new columns of year, quarter, and month for the two fact tables Building a cube. ◦ Define a new dimension Dim Time from Manufacturing Fact table Customize the cube: ◦ Link two fact tables in a cube ◦ Define new primary key for Dim Time ◦ Define calculated measures ◦ Relate dimensions to measures 24
T-SQL Expressions for DS View Definition Manufacture YearOfManufacture CONVERT(char(4),YEAR(DateOfManufacture)) QuarterOfManufacture CONVERT(char(4), YEAR(DateOfManufacture)) + CASE WHEN MONTH (DateOfManufacture) BETWEEN 1 AND 3 THEN 'Q1' WHEN MONTH (DateOfManufacture) BETWEEN 4 AND 6 THEN 'Q2' WHEN MONTH (DateOfManufacture) BETWEEN 7 AND 9 THEN 'Q3' ELSE 'Q4' END MonthOfManufacture CONVERT(char(4), YEAR(DateOfManufacture)) + RIGHT('0'+CONVERT(varchar(2), MONTH(DateOfManufacture)),2) 25
T-SQL Expressions for DS View Definition Inventory YearOfInventory CONVERT(char(4),YEAR(DateOfInventory)) QuarterOfInventory CONVERT(char(4), YEAR(DateOfInventory)) + CASE WHEN MONTH (DateOfInventory) BETWEEN 1 AND 3 THEN 'Q1' WHEN MONTH (DateOfInventory) BETWEEN 4 AND 6 THEN 'Q2' WHEN MONTH (DateOfInventory) BETWEEN 7 AND 9 THEN 'Q3' ELSE 'Q4' END MonthOfInventory CONVERT(char(4), YEAR(DateOfInventory)) + RIGHT('0'+CONVERT(varchar(2), MONTH(DateOfInventory)),2) 26
Data Source View
New columns 27
Select Measures Page
Uncheck Manufacture
Fact Count
28
Review New Dimensions Page
Rename Manufacturing Fact to Dim Time 29
New dimension Created from the Fact table
The finished cube
30
Cube Structure
31
MEASURES
32
Facts
Measurements associated with a specific business process.
Types of measures ◦ Most facts are additive (calculative), such as sum; others are semi-additive (those that can be added along some dimensions, not along others), non-additive (such as max, average), or descriptive (e.g. factless fact table).
Many facts can be derived from other facts. So, non additive facts can be avoided by calculating it from additive facts.
33
Calculated measures
The definition of calculated measure is stored in the OLAP cube itself. The actual values that result from a calculated measure are not calculated, however, until a query containing that calculated measure is executed. The results of that calculation are then cached in the cube. The cached value is then delivered to any subsequent users requesting the same calculation.
The expressions of calculation are created using a language known as Multidimensional Expression Language (MDX) script. MDX is different from T-SQL. It is a special language with features designed to handle the advanced mathematics and formulas required by OLAP analysis. This is not found in T-SQL. 34
Define Format String “#, #” for measures:
AcceptedProduct, RejectedProject 35
Defining a format string
36
37
38
Define Calculated Measures
39
DIMENSIONS
40
Managing Dimensions
41
Managing Dimensions
42
Relating Dimensions to Measure Groups 43
Completed Dimension Definitions
44
Types of Dimensions
Fact dimensions: the Dimensions created from attributes in a fact table Parent-Child dimensions: Built on a table containing a self-referential relationship, such as a parent attribute. Role playing dimensions: related to the same measure group multiple times; each relationship represents a different role the dimension play; for example, time dimension plays three different roles: date of sale, data of shipment, and date of payment Reference dimensions: Not related directly to the measure group but to another regular dimension which in turn related to the measure group Data mining dimensions: the information discovered by data mining Many-to-many dimensions: e.g. multiple ship to addresses Slowly changing dimensions ◦ Type 1 SCD – no track ◦ Type 2 SCD – tracking the entire history, adding four attributes: SCD Original ID, SCD Start Date, SCD End Date, SCD Status ◦ Type 3 SCD – Similar to Type 2 SCD but only track current state and the original state; two additional attribute: SCD Start Date, SCD Initial Value 45
CUBE DESIGN TABS
46
Understanding the Cube Designer Tabs Cube Structure: Use this tab to modify the architecture of a cube.
Dimension Usage: Use this tab to define the relationships between dimensions and measure groups, and the granularity of each dimension within each measure group.
Calculations: Use this tab to examine calculations that are defined for the cube, to define new calculations for the whole cube or for a subcube, to reorder existing calculations, and to debug calculations step by step by using breakpoints.
KPIs: Use this tab to create, edit, and modify the Key Performance Indicators (KPIs) in a cube. Actions: Use this tab to create or modify drillthrough, reporting, and other actions for the selected cube..
Partitions: Use this tab to create and manage the partitions for a cube. Partitions let you store sections of a cube in different locations with different properties, such as aggregation definitions.
Perspectives: Use this tab to create and manage the perspectives in a cube. A perspective is a defined subset of a cube, and is used to reduce the perceived complexity of a cube to the business user.
Translations: Use this tab to create and manage translated names for cube objects, such as month or product names.
Browser: Use this tab to view data in the cube.
ISQS 6339, Data Mgmt & Business Intelligence 47
Key Performance Indicators (KPIs)
Digital dashboard Creating a KPI ISQS 6339, Data Mgmt & Business Intelligence 48
The MDX expression for KPI Status Expression (MaxMinManufacturingDM) Case When ROUND([Measures].[percent Rejected],4) < 0.0103
Then 1 When ROUND([Measures].[percent Rejected],4) >= 0.0103 ROUND([Measures].[percent Rejected],4) >= 0.0104 Then .5
When ROUND([Measures].[percent Rejected],4) >= 0.0104 ROUND([Measures].[percent Rejected],4) >= 0.0105 Then 0 When ROUND([Measures].[percent Rejected],4) >= 0.0105 AND ROUND([Measures].[percent Rejected],4) >= 0.0106 Then -.5
End Else -1 AND AND ISQS 6339, Data Mgmt & Business Intelligence 49
Calculated measure 50
KPI definition and deployment 51
KPI Browser
Browser View
ISQS 6339, Data Mgmt & Business Intelligence 52
Actions
Instructions stored inside the cube Allow the OLAP cubes to “reach out and touch someone.” Enable us to define commands, statements, and directives that are to be executed outside of the cube Linked to certain objects in the cube, which can be enacted as a menu when a user is browsing the objects. The user can select one of the these actions to accomplish certain tasks.
ISQS 6339, Data Mgmt & Business Intelligence 53
Types of Actions
Action ◦ Dataset ◦ Proprietary ◦ Rowset - Retrieve a rowset.
◦ Statement ◦ URL Drillthrough Action. Defines a dataset to be returned as a drillthrough to a more detailed level Report Action. Launch a SQL Server 2005 Reporting Services report ISQS 6339, Data Mgmt & Business Intelligence 54
Defining Actions
55
Perspectives
56
Translations
57
Q & A
Conceptual level ◦ What are rationale behind the structure of “Data Source”, “Data Source View” and “Cube”?
◦ Why time dimension is so important in a data mart?
◦ Why is the multi-levels of dimensions, such as Material-MachineType-Machine in MaxMinManufacturingDM, useful? ◦ Why do you need to change the primary key of DimTime after it was created from the MaxMinManufacturingFact table?
◦ Can you summarize a number of main differences between a regular database design and a data mart design?
Technical level ◦ After you made changes in a data source node why do you have to check “Mapping” in the data destination node again?
◦ When there is a red wave line under an object, such as a table during cube design, what does it imply? How to solve it? Specifically, when a fact table has such a problem how could it be fixed?
◦ ◦ Why not all dimensions appear in the cube structure diagram? What is the difference between the variable names in the format of Name and [Name]? ◦ Do you understand the parameters configured in the data flow tasks, such as those in data sources, data destination, Aggregate node, Derived Column node, etc? Any other questions?
58
Data Mart Application Development Debugging Problem 0: You cannot find your database entry.
Problem 1: The source node is red after running a data flow task ◦ Causes?
Problem 2: The destination node is red after running a data flow task ◦ Causes?
Problem 3: Even though you redefined the source node, the problem remains.
Open problems ◦ What are frequently encountered problems in ETL application implementation?
◦ What are the problems you encountered in building a cube? 59