Sunday, 19 February 2017

Create LinkTable For Fact Tables of Different Grains

Create LinkTable For Fact Tables of Different Grains

If fact tables have different grains, we need to create a linktable to remove synthetic key and make data modeling to be star schema.
Step:
1.  Create composite key in each fact table that will associate the rows in the fact table to the linktable.
2.  Use concatenate or join to create linktable
3.  Drop the key fields that have been added to the linktable from the fact tables

Example:
Sales:
LOAD
AutoNumber(Floor(Date)&'-'& Store&'-'& Product,'Composite_Key1') As Composite_Key1,
[Store],
Product,
Quantity,
Date,
Time,
Amount
FROM
E:\Source\Sales.txt
(txt, codepage is 936, embedded labels, delimiter is ',', msq);
Budget:
LOAD AutoNumber(Floor(Date)&'-'& Store&'-'& Product,'Composite_Key1') As Composite_Key1,
[Store],
Product,
Date,
Budget
FROM
E:\Source\Budget.txt
(txt, codepage is 936, embedded labels, delimiter is ',', msq);
LinkTable:
Load Distinct Composite_Key1,Store,Date,Product Resident Sales;
Join(LinkTable)
Load Distinct Composite_Key1,Store,Date,Product Resident Sales;
Drop Fields Store,Date,Product From Sales,Budget;


This produced data model like the following:



Stock:
Load AutoNumber(Store&'-'&Product,'Composite_Key2') As Composite_Key2,
[Store],
Product,
In_Stock
FROM
E:\Source\Stock.txt
(txt, codepage is 936, embedded labels, delimiter is ',', msq);
Join(LinkTable)
Load Distinct Composite_Key2,Store,Product Resident Stock;
Drop Fields Store,Product From Stock;

the data model looks like the following:




Friday, 3 February 2017

Hierarchy Function In Qlikview



In Qlikview Hierarchy function consists of following parameters:
Hierarchy (NodeID, ParentID, NodeName, [ParentName], [PathSource], [PathName], [PathDelimiter], [Depth]) (loadstatement | selectstatement)
Here is a quick description of each of the parameters:
NodeID - is the name of the field that contains the node id.
ParentID - is the name of the field that contains the node id of the parent node.
NodeName - is the name of the field that contains the name of the node.
ParentName - is a string used to name the new ParentName field. If omitted, this field will not be created.
PathSource - is the name of the field that contains the name of the node used to build the node path. This is an optional parameter. If omitted, NodeName will be used.
PathName - is a string used to name the new Path field, which contains the path from the root to the node. This is an optional  parameter. If omitted, this field will not be created.
PathDelimiter - is a string used as delimiter in the new Path field. This is an optional parameter. If omitted, ‘/’ will be used.
Depth - is a string used to name the new Depth field, which contains the depth of the node in the hierarchy. This is an optional parameter. If omitted, this field will not be created.

Here is an example for Qlikview Hierarchy:
 // made an cooperation organization structure table.

 ORGANIZATION:
LOAD * INLINE [
    ROLE, REPORTINGMANAGER, LEVELOFBUSINESSHEAD
    Trainee, Investment Manager, Marketing Manager
    Junior Consultant, Sales Manager, Marketing Manager
    Consultant, Operation Manager, Marketing Manager
    Senior Consultant, Operation Manager, Marketing Manager
    Investment Manager, Marketing Manager, Domestic Headquarters
    Operations Manager, Marketing Manager, Domestic Headquarters
    Sales Manager, Marketing Manager, Domestic Headquarters
    Marketing Manager, Domestic Headquarters, Board
    Oversea General Manager, Oversea Headquarters, Board
    Domestic Headquarters, CEO, Board
    Oversea Headquarters, CEO, Board

];



// declared the hierarchy as below

TREE_VIEW:

LOAD Distinct ROLE as VALUE, ROLE & '-ROLE' as NODE_ID, REPORTINGMANAGER & '-REPORTINGMANAGER' as PARENT_NODE_ID resident ORGANIZATION;
LOAD Distinct REPORTINGMANAGER as VALUE,REPORTINGMANAGER & '-REPORTINGMANAGER' as NODE_ID, LEVELOFBUSINESSHEAD & '-LEVELOFBUSINESSHEAD' as PARENT_NODE_ID resident ORGANIZATION;
LOAD Distinct LEVELOFBUSINESSHEAD as VALUE,LEVELOFBUSINESSHEAD & '-LEVELOFBUSINESSHEAD' as NODE_ID,  LEVELOFBUSINESSHEAD & '-LEVELOFBUSINESSHEAD' as PARENT_NODE_ID resident ORGANIZATION;


HIERARCHY_TABLE:
Hierarchy(NODE_ID_H,PARENT_NODE_ID_H, ID, PARENT_NAME, NAME, Organization_Structure) load
NODE_ID,
NODE_ID as NODE_ID_H,
PARENT_NODE_ID as PARENT_NODE_ID_H,
VALUE as ID,
VALUE as NAME
resident TREE_VIEW;


//created a list box, in the properties,select the show as tree view check box,the image shows below: