The document discusses different ways to control script execution flow in Qlik, including using loops, IF statements, switches, subroutines, and exiting scripts. It provides examples of when flow control is needed, such as loading cross tables or files divided across worksheets. Subroutines allow defining reusable code that can be called multiple times with parameters. Load statement prefixes like cross, generic, and hierarchy can transform table structures during loading.
The document discusses different ways to control script execution flow in Qlik, including using loops, IF statements, switches, subroutines, and exiting scripts. It provides examples of when flow control is needed, such as loading cross tables or files divided across worksheets. Subroutines allow defining reusable code that can be called multiple times with parameters. Load statement prefixes like cross, generic, and hierarchy can transform table structures during loading.
The document discusses different ways to control script execution flow in Qlik, including using loops, IF statements, switches, subroutines, and exiting scripts. It provides examples of when flow control is needed, such as loading cross tables or files divided across worksheets. Subroutines allow defining reusable code that can be called multiple times with parameters. Load statement prefixes like cross, generic, and hierarchy can transform table structures during loading.
Advanced Transformations in Script Advanced Transformations in script
Script execution flow controls
Different Load types Load statement prefixes • In some cases, there is a need to control the flow of execution and • from a file Qlik prefixes can be applied in any type of load statement. change it, in order to load more complex file or table structures, • from data defined in the script Some prefixes allow table and data transformations. execute external function, loop through field values or tables in the • from a previously loaded table app, etc. • from a web page • CrossTable: Used to transform cross tables into straight • from the result of a subsequent Select statement tables. Some examples that require the usage of flow controls in the script are • from scratch, by generating data automatically Crosstable (attribute_field_name, data_field_name [ the following: , n ] ) Load/ Select * from PivotTable; • from analytic connections • Loading cross tables with more than one pivoting dimension. • Generic: Used to load generic tables (tables that • Loading tables divided in separate files (or worksheets) that need to Load statement syntax represent element properties in a table form). be loaded as a single table. Generic LOAD/SELECT * from GenericTable1; • Stopping script execution at any given point (early termination of the LOAD [ distinct ] script execution after a specific script point). • Hierarchy: Used with parent-child hierarchy tables. This fieldlist • Generating information tables and metadata of the current tables and [( from file [ format-spec ] | from_field prefix transforms these tables into tables where all the fields. fieldAsSource [format-spec] | inline data [ hierarchy represented as levels. • Generating QVD files or other exported formats based on the current format-spec ] | resident table-label | • HierarchyBelongsTo: Similar to Hierarchy prefix, but in tables and fields loaded into the script. autogenerate size ) | extension this case the resulting table contains all ancestor-child • Creating complex calculations in tables that require recursive pluginname.functionname([script] iterations. relations of the hierarchy. tabledescription)] Hierarchy (NodeID, ParentID, NodeName, [ParentName], • Iterating through the values of a field. [ where criterion | while criterion ] [PathSource], [PathName], [PathDelimiter], • Creating a piece of code that can be reusable and applicable with [ group by groupbyfieldlist ] [Depth])(loadstatement | selectstatement) different parameters by using a subroutine. [ order by orderbyfieldlist ] • Semantic: Loads tables containing relations between records. To control the execution flow in the script, you can use the following: Subroutines in Qlik Semantic SELECT/LOAD Object1 as Object, Relation1 as • Loops - recurrent execution of a piece of code several times. Relation, Object2 as Object , Relation2 as Relation • Do…While Qlik allows you to define you own formulas using from table1; • For…Next Subroutines. • Subroutines are reusable pieces of code that can • For Each…Next Subroutine example in Qlik be defined in the script and called as many times SUB LoadAndStore (TableName, TablePath, QVDPath) • IF statements - decision trees to evaluate certain conditions and LOAD * From $(TablePath)$(TableName).csv; execute a piece of code or another. as needed in the script. STORE $(TableName) INTO $(QVDPath)$(TableName).qvd; • You define the code and the parameters in them. A • Switch Case - decision branches based on a result. LET vRowCount = Num(NoOfRows('$(TableName)'),'#,##0'); subroutine does not need to have parameters if not TRACE --'$(TableName)' row count: $(vRowCount); • Subroutines - reusable piece of code that can be defined with needed. END SUB parameters and can be executed using a call function as many times as needed. This allows you to create your own custom functions. 1 • Subroutines simplify the script and make the code // Loading data tables CALL LoadAndStore ('Sales', '..\Data\','..\QVDs\') • Exit script statement - script termination at any point of the script. easier to maintain and debug.