Qlikview Notes
Short Description
It has some qlikview related notes information....
Description
Keyboard Shortcuts in QlikView : Ctrl+R-> Reload Ctrl+E-> Edit Script Ctrl+T-> Table Viewer Ctrl+Alt+V-> Variable overview Ctrl+Alt+E-> Expression overview Ctrl+Alt+S->Sheet Properties window Alt+Enter->Sheet OBJECT Properties window Holding CTRL+object will leads to copy to another sheet.. Holding CTRL+Shift+object will leads to creating the link object to another sheet..
Load types: 1. Main Load -- Which loads from any file/data base in Edit script(Ctrl+E) 2. Resident load resident table.
-- Fetching some of fields from main table and creating new
3. Inline load -- Creating a table in Qlikview itself. 4. Binary Load
-- Which appends existing QVW file with new code
Short cuts: 1. Edit script – Ctrl + E this we are using this.
-- Which is used to load data from any format data. For
2. Reload – Ctrl +R -- Which loads(Refreshes) the data into qlikview engine 3. Table Viewer – Ctrl + T -- Having Schema design (Automatically detects the relation b/w table if same column exists in multiple tables with same name)
Different ways to load data in to Qlikview: Introduction: There are different ways and methods to load data into Qlikview. Explained below with examples and uses of methods of loading data into qlikview. Types: 1. Loading data from the file. 2. Inline Load 3. Resident Load
4. Incremental Load 5. Binary Load 6. Add Load 7. Buffer Load 1. 1. Loading Data from File: •
This method is normal method of loading data into the Qlikview application.
•
Load data from files like Excel,MSDB,CSV,Txt files etc., can be done by creating ODBC and connecting to your database directly.
Example: LOAD A, B FROM [C:\filename.xls] (biff, embedded labels, table is Data$); 1. 2. Inline Load: •
The second method of loading is Inline Load where the user can define their own data and load within Qlikview.
•
The Inline data can be defined in the inline Data Wizard .
InsertàLoad Dataà Inline Data. Example: LOAD * INLINE [ A B C ]; 1. 3. Resident Load: •
Loading data from already loaded Qlikview table is possible using Resident Load.
•
Transformations and Calculations can be performed in the resident load script.
•
Loading a existing field or a succeeding table is possible too.
Example:
Employees: Select Empname, HireDate, Salary, Incentives From Employee; Load Empname, Month(HireDate), Salary + Incentives as ‘GrossSalary’ Resident Employees; 4. Incremental Load: • •
Incremental load is used to load only the new or changed records. It will be very helpfull where a database is big.
•
This involves loading old data from the QVD and new records from the database and combine into single QVD.
Example: SQL SELECT PrimaryKey, X, Y FROM DB_TABLE WHERE ModificationTime >= #$(LastExecTime)# AND ModificationTime < #$(BeginningThisExecTime)#; Concatenate LOAD PrimaryKey, X, Y FROM File.QVD; STORE QV_Table INTO File.QVD; 1. 5. Binary Load: Loading data from one qlikview file is called Binary Loading. The data model of one QVW file is copied from RAM to disk in 0s and 1s for another qvw file. This Binary Load will be more usefull when you want to enhance the already built qvw with the same metrices defined.]
Binary Load is used to hide the scripts from Users. First one Qlikview file with all the scripts required for the reports are created and then binary load this into another file by using
Script -> Qlikview File -> Select the Qlikview file created earlier. You can load only one qlikview file by using Binary load. By using this Binary Load Scripts are hidden from users. Example: Binary c:\order.qvw; 1. 6. Add Load: Add Load is used to append or concatenate the data from one table to other table. During a partial reload the QlikView table, for which a table name is generated by the add load/add select statement (provided such a table exists), will be appended with the result of the add load/add select statement. Since it wont check for duplicates, it is required us suitable where condition in the script. Example: LOAD ENO, ENAME from Employees.csv; ADD LOAD ENO, ENAME from Employees1.csv Where Not Exists(ENO); 1. 7. Buffer Load: Buffer load helps to create the QVD files automatically. The created QVD will be maintained as defined in User Preferencesà Locations. Example: Buffer select * from Employees.csv;
Synthetic Keys and Synthetic Table: If you find more than one common fields it will leads to synthetic keys. The table which shows the synthetic keys that we call it as Synthetic Table. How to remove synthetic keys: 1. Joins 2. Concatenate 3. Commenting 4. Renaming the fields 5. Qualify & Un-Qualify
Joins: The QlikView script functions JOIN, KEEP and CONCATENATE can sometimes be used to solve the same problem, but there are important differences that should be understood. Examine the sample tables below. Note that they share one common field name, "Key". Also note that Table1 has a Key value "3" that is not present in Table2 and that Table2 has a key 4 that is not present in Table1.
Table1 Key
Table2 A
Key
C
1 A1
1 C1
2 A2
2 C2
3 A3 4 C4 Type of Joins: JOIN will combine rows where the Key value matches. • •
The keyword OUTER will also retain rows that do not match rows in the other table. The keyword LEFT will retain rows from the left table but only matching rows from the right table
•
The keyword RIGHT will retain rows from the right table but only matching rows from the left table
•
The keyword INNER will retain rows matching the left table and right table
Joins Here's what the merged table will look like after the different join methods. Note that QlikView merge the two tables after a Join. Note: The explicit join keyword (= Outer Join) in QlikView script language performs a full join of the two tables. The result is one table. In many cases such joins will result
in very large tables. One of the main features of QlikView is its ability to make associations between tables instead of joining them, which greatly reduces memory usage, increases processing speed and offers enormous flexibility. Explicit joins should therefore be generally avoided in QlikView scripts. The keep functionality was designed to reduce the number of cases where you need to use explicit joins
OUTER JOIN (Table1)
LEFT JOIN (Table1)
Key
Key
A
C
A
C
1 A1
C1
1 A1
C1
2 A2
C2
2 A2
C2
3 A3
-
3 A3
-
4-
C4
RIGHT JOIN (Table1)
INNER JOIN (Table1)
Key
Key
A
C
A
C
1 A1
C1
1 A1
C1
2 A2
C2
2 A2
C2
4-
C4
Keep The keep prefix between two load or select statements has the effect of reducing one or both of the two tables before they are stored in QlikView, based on the intersection of table data. The keep keyword must always be preceded by one of the prefixes inner,left or right. The selection of records from the tables is made in the same way as in a corresponding join. However, the two tables are not joined and will be stored in QlikView as two separately named tables.
LEFT KEEP Table1 Key
Table2 A
Key
C
1 A1
1 C1
2 A2
2 C2
3 A3
3-
RIGHT KEEP Table1 Key
Table2 A
Key
C
1 A1
1 C1
2 A2
2 C2
4-
4 C4
INNER KEEP Table1 Key
Table2 A
Key
C
1 A1
1 C1
2 A2
2 C2
Concatenate Now let's look at Concatenate. Concatenate appends the rows of one table to another. Concatenate never merges any rows. The number of rows in a concatenated table is always the sum of the rows from the two input tables. Here's what our sample data will look like after Concatenate.
CONCATENATE (Table1) LOAD * RESIDENT Table2;
Key
A
C
1 A1 1
C1
2 A2 2
C2
3 A3 4
C4
Rows with like Key values are not merged together. The rows from Table2 are simply appended to Table1. Because the tables have different fields, rows will have null values for the fields from the "other" table. Qualify and Unqualify: Qualify statements renames all the fields with the table name prefix which are mentioned in the statement. QUALIFY *; it can be used above the table name. * is to rename all the field name in the table. Otherwise u can also specify each field that u wanted to rename. UNQUALIFY is reverse process of QUALIFY statement. If u r not using the UNQUALIFY statement after using QUALIFY, it ll rename all fields of all the table below the QUALIFY. QUALIFY *; //or QUALIFY OrderID, CustomerName; Orders:
//Table Name
LOAD OrderID,
OrderName, CustomerName, FROM xxx.xls; UNQUALIFY *; If u use * then, ur fields ll be like this: Orders.OrderID Orders.OrderName Orders.CustomerName
If not using *, it ll rename oly the fields u have mentioned.
a good way to use QUALIFY and UNQUALIFY to bring in new tables and you want to link on one known field, but you aren't sure whether you will have name clashes with the rest.
QUALIFY *; UNQUALIFY OrderID; Orders: LOAD OrderID, OrderName, CustomerName, FROM xxx.xls;
UNQUALIFY *; This will result in a table with fields like this: OrderID Orders.OrderName Orders.CustomerName
Imp Statements 1) JOIN->Left,Right,Outer(Default),inner 2) KEEP(Left,Right,Outer(Default),inner) Same as join, but it keeps both the source table WITH MODIFICATION ie., It filters data over tables depending upon on the join 3) CONCATENATE: No matter what, it simply appends all the rows to the concatenated table within the appropriate field!! 4) NOCONCATENATE: explicitly specifying that, there SHOULD NOT BE any concatenation even though there are similar fields!! 5) MAPPING: Its just a sort of reference table, thereby values can fetched from that mapping table which can have only 2 fields(One for look up and another for the fetch able statements) 6) COMMENT TABLE & FIELD: COMMENT TABLE [Tab Name] WITH ' Hai how r u'; COMMENT FIELD [Field Name] WITH ' Hai how r u';
Concatenate happens in different ways. 1. Automatic Concatenation 2. Forced Concatenation 3. No Concatenation In this Part 1 i will cover Automatic Concatenation Automatic Concatenation As stated above,when field names and field numbers of 2 or more tables is same then the tables are concatenated into one table. Order of the columns in tables does not matter. Also The Sum of records in the resulting table is the Sum of the number of records in Table 1 and Table 2. Let us load first table and see it in the table viewer
As you can see that this table has following 4 rows.
Let us now load 2 tables, with same name and number of columns. Table Cust_1 has 4 rows and table Cust_2 has 3 rows. Order of columns are different. Observe Table viewer and number of rows in the resulting table.
As you can see the number of rows in the resulting table is 7 rows. The Sum of records in the resulting table is the Sum of the number of records in Table 1 and Table 2.
For details on Forced Concatenation and Preventing Concatenation, please visit Concatenate Forced Concatenation If two or more tables do not have exactly same name and number of fields, it is still possible to concatenate them by using concatenate keyword before the load statement. Let us load 2 tables with different sets of fields
Concatenation do not occur as Tables have different set of fields.
Now to force concatenation use Concatenate key word before the load of second table
Observe that the tables are concatenated and numbers of rows is 7 i.e. Sum of rows in Table1 and Table2.
Preventing Concatenation If the field names and number is same in 2 or more tables them QlikView performs an automatic concatenation but it is possible to prevent this automatic concatenation by using NoConcatenate Let us load the same tables as in Part1 i.e. Table Cust_1 and Cust_2. These tables have same set of fields so they should get concatenated but this time load them by using NoConcatenate
Table viewer shows 2 tables. Automatic concatenation was prevented by using NoConcatenate. Note that 2 tables are created but since they have more than one field in common, it created a synthetic table. Resolving synthetic table and keys is a different topic and you can get details on it from my earlier blog on “Resolving synthetic keys”. For this excercise we wanted to see that using NoConcatenate we can avoid automatic concatenation. Summary : 1. Automatic concatenation occurs when the name and number of fields are same in 2 or more tables 2. Forced concatenation is done by using Concatenate keyword. It will concatenate tables even if they do not have same set of fields 3. No Concatenate can be used to prevent automatic concatenation, even if tables have same set of fields.
View more...
Comments