Avoiding data model conflicts: Synthetic Key

Dealing with synthetic keys
When any two tables share more than one common field, QlikView creates a complex
key, or synthetic key, to try and associate both tables through the combination of all
of the common fields between them. This takes the form of an additional table
containing the shared fields and an additional key field added to all involved tables.
There are several methods we can use to remove synthetic keys:

1. Renaming / Qualifying
• We can rename those fields that are a part of the synthetic key but should not be a
part of the association between the two tables.

2. Removing Fields
• We can remove conflicting fields from one of the two tables. To remove a field, we
just erase the corresponding line of code from the Load script.

3.Composite Key
• We can create an explicit complex key with the concatenation of all common fields
that actually represent the link between the two tables.
Note: After creating the new complex key, we can remove the conflicting fields from
either table.

Dealing with circular references
Similar to how synthetic keys are created, a circular reference can also be the result
of unwanted associations in our data model and, as such, they can be fixed using the
same principles described earlier like Renaming fields, Qualifying fields or using a
Resident Load .

Using 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 an existing field or a succeeding table is possible too.

Using inline Data

Using Inline Load the user can define their own data and load within Qlikview scritpt.
The Inline data can be defined in the inline Data Wizard / Statement.

this means that the columns in both tables are compared and the join is made over those columns that have the same column names. This means that the rows for both tables are included in the resulting table. and RIGHT KEEP applies here as did with the JOIN statement. LEFT. and RIGHT. or right join respectively. null values will be shown for the columns that are unique to the first table. with a small difference. This has the following results: • INNER JOIN: Only rows that can be matched between both tables will be kept in the result. • OUTER JOIN: All rows will be kept in the result. the KEEP statement keeps both original tables and filters (keeps) rows in one table based on matching rows in another table. which performs an inner. the match will be made over the distinct combinations of those columns. The same logic for INNER. The CONCATENATE statement . • RIGHT JOIN: All rows from the second table and those rows from the first table which have a corresponding key in the second table. null values will be shown for the columns that are unique to the second table. It is used to join the table that is being loaded to a previously loaded table. When rows do not have a corresponding row in the other table. When no prefix is specified. will be included in the result. will be included in the result. The KEEP statement The KEEP statement works in the same way that the JOIN statement does. QlikView performs an outer join.]. Manipulating tables The JOIN statement The JOIN statement is a prefix to the LOAD statement. IMP : By default. • LEFT JOIN: All rows from the first table and those rows from the second table that have a corresponding key in the first table. rows that do not have a corresponding value in the other table will get null values for the fields that are unique to that table. The JOIN statement can be prefixed with the statements INNER. the join will be made to the table loaded directly before the JOIN statement. that table can be joined to by supplying its name in parentheses. the missing columns are assigned null values. OUTER. When no match is found. LEFT. OUTER. outer. left. When no match is found. This means that if multiple columns are shared between tables. this is the default join type that will be used. If the table to join to was loaded somewhere earlier in the script. The two tables are joined using a natural join. Note: When using just the bare JOIN statement. Instead of joining the result in a single table.

When no value is specified. in reality. QlikView will implicitly concatenate Table2 onto Table1. we tell QlikView that we want to create a mapping table. At the end of the script. QlikView will automatically concatenate them. that is looked up in the mapping table. We can prevent this from happening by prefixing the LOAD statement for Table2 with the NOCONCATENATE statement. there is an easy way to export a QlikView table to an external QVD file. a field value or expression from the source table. The NOCONCATENATE statement When two tables share the exact same columns. here we used the value Unknown. . the STORE statement. this statement appends the rows of one table to another table. Note: However. Using MAPPING tables The MAPPING statement provides an alternative to the JOIN statement in a very specific scenario: when you want to replace a single key value with a value from a lookup (mapping) table. even if a table with the same columns already exists. • It is a temporary table. the search value is returned. Storing tables In an environment with multiple documents. QlikView automatically removes the table from the data model. The result of this script is a single table. it is very likely that we will want to reuse the same table in different apps. By prefixing the LOAD statement with the MAPPING statement. and are a very useful aid for understanding the data. Adding comments The COMMENT statement can be used to add comments to tables and fields. Fortunately. • An optional value that specifies what value to use when no match is found in the mapping table.The CONCATENATE statement is also a prefix to the LOAD statement. if two tables contain the exact same columns. This statement instructs QlikView to create a new table. the first being the lookup value and the second being the mapping value to return. These comments will be shown when hovering the mouse cursor over table and field names in various dialogs and the Table Viewer window. This is a specific type of table that has the following properties: • It can only have two columns. We can prevent this from happening by prefixing the LOAD statement for Table2 with the NOCONCATENATE statement. Use of The ApplyMap() function : It uses three parameters: • The name of the mapping table to use • The search value. but instead of matching and merging rows between tables.

.qvd. RENAME FIELD [%ABCD] TO [ABCD ID]. The third line also deletes the field [%ABCD]. Renaming tables and fields Renaming tables or fields in QlikView is done using the RENAME statement. those are left unaffected.STORE [ABC] INTO '. The first line deletes the table [ABC]. . Deleting tables and fields Deleting tables or fields is done using the DROP statement. DROP FIELD [%ABCD].qvd' (qvd). RENAME TABLE [ABC] TO [XYZ]. DROP TABLE [ABC]. The other option is (txt) to store the table in text format.qvd suffix at the end of the statement tells QlikView to use the QVD format. DROP FIELD [%ABCD] FROM [ABC]. The second line deletes the field [%ABCD].\Data Files\QVDs\ABC. If any other tables contain the same field. RENAME FIELD [ABCD] to [AB]. [WXYZ] to [WX]. This tells QlikView to store the table [ABC] into the sub-folder DataFiles\QVDs with the filename ABC. but only from the [ABC] table. The .