Script Syntax and Chart Functions

June 2, 2016 | Author: Anonymous msnAdwqjS | Category: N/A
Share Embed Donate


Short Description

qlik manual...

Description

Script syntax and chart functions Qlik Sense® 2.1.1 Copyright © 1993-2015 QlikTech International AB. All rights reserved.

Copyright © 1993-2015 QlikTech International AB. All rights reserved. Qlik®, QlikTech®, Qlik Sense®, QlikView®, Sense® and the Qlik logo are trademarks which have been registered in multiple countries or otherwise used as trademarks by QlikTech International AB. Other trademarks referenced herein are the trademarks of their respective owners.

Contents 1 What is Qlik Sense?

18

1.1 What can you do in Qlik Sense?

18

1.2 How does Qlik Sense work?

18

The app model The associative experience Collaboration and mobility 1.3 How can you deploy Qlik Sense?

18 18 18 18

Qlik Sense Desktop Qlik Sense Server 1.4 How to administer and manage a Qlik Sense site

19 19 19

1.5 Extend Qlik Sense and adapt it for your own purposes

19

Building extensions and mashups Building clients Building server tools Connecting to other data sources 2 Script syntax

19 19 19 19 20

2.1 Introduction to script syntax

20

2.2 What is Backus-Naur formalism?

20

2.3 Script statements and keywords

21

Script control statements Script control statements overview Call Do..loop Exit script For..next For each..next If..then..elseif..else..end if Sub..end sub Switch..case..default..end switch Script prefixes Script prefixes overview Add Buffer Bundle Concatenate Crosstable First Generic Hierarchy HierarchyBelongsTo Image_Size Info Inner IntervalMatch Join

Script syntax and chart functions - Qlik Sense, 2.1.1

21 22 23 24 25 26 27 30 31 32 33 33 37 38 39 40 41 41 42 42 43 44 45 46 47 49

3

Contents Keep Left Mapping NoConcatenate Outer Replace Right Sample Semantic Unless When Script regular statements Script regular statements overview Alias Binary Comment field Comment table Connect Declare Setting up a new field definition Re-using an existing field definition Derive Direct Query Direct Discovery field lists Directory Disconnect Drop field Drop table Execute FlushLog Force Load Format specification items Character set Table format Delimiter No eof Labels Header is Record is Quotes XML KML Let Map NullAsNull

Script syntax and chart functions - Qlik Sense, 2.1.1

50 50 52 53 53 54 55 57 57 58 58 59 59 65 66 67 68 69 70 70 71 72 73 76 78 79 79 80 80 82 82 82 89 90 90 91 92 92 93 93 94 95 95 95 96 97

4

Contents NullAsValue Qualify Rem Rename field Rename table Search Section Select Set Sleep SQL SQLColumns SQLTables SQLTypes Star Store Tag Trace Unmap Unqualify Untag Working directory Qlik Sense Desktop working directory Qlik Sense working directory 2.4 Working with variables in the data load editor

97 98 99 99 100 101 101 102 104 105 105 106 107 107 108 109 110 111 111 112 112 113 113 113 114

Deleting a variable Loading a variable value as a field value Variable calculation System variables System variables overview HidePrefix HideSuffix Include OpenUrlTimeout StripComments Verbatim Value handling variables Value handling variables overview NullDisplay NullInterpret NullValue OtherSymbol Number interpretation variables Number interpretation variables overview Currency formatting Number formatting

114 115 115 116 116 118 119 119 120 120 120 121 121 121 121 122 122 123 123 123 123

Script syntax and chart functions - Qlik Sense, 2.1.1

5

Contents Time formatting BrokenWeeks DateFormat DayNames DecimalSep FirstWeekDay LongDayNames LongMonthNames MoneyDecimalSep MoneyFormat MoneyThousandSep MonthNames ReferenceDay ThousandSep TimeFormat TimestampFormat Direct Discovery variables Direct Discovery system variables Teradata query banding variables Direct Discovery character variables Direct Discovery number interpretation variables Error variables Error variables overview ErrorMode ScriptError ScriptErrorCount ScriptErrorList 2.5 Script expressions 3 Visualization expressions

124 125 125 126 126 126 127 127 127 127 128 128 128 129 129 129 129 129 131 131 132 133 133 134 134 135 135 136 137

3.1 Defining the aggregation scope

137

3.2 Syntax for sets

139

3.3 Set modifiers

139

Based on another field Based on element sets (a field value list in the modifier) Forced exclusion Set modifiers with set operators Set modifiers using assignments with implicit set operators Set modifiers with advanced searches Set modifiers with dollar-sign expansions Set modifiers with implicit field value definitions 3.4 Visualization expression and aggregation syntax

140 140 140 141 142 142 143 143 144

General syntax for chart expressions General syntax for aggregations 4 Operators 4.1 Bit operators

Script syntax and chart functions - Qlik Sense, 2.1.1

144 145 146 146

6

Contents 4.2 Logical operators

147

4.3 Numeric operators

147

4.4 Relational operators

148

4.5 String operators

149

5 Functions in scripts and chart expressions 5.1 Aggregation functions Using aggregation functions in a data load script Using aggregation functions in chart expressions Aggr - chart function Basic aggregation functions Basic aggregation functions overview Basic aggregation functions in the data load script Basic aggregation functions in chart expressions FirstSortedValue FirstSortedValue - chart function Max Max - chart function Min Min - chart function Mode Mode - chart function Only Only - chart function Sum Sum - chart function Counter aggregation functions Counter aggregation functions in the data load script Counter aggregation functions in chart expressions Count Count - chart function MissingCount MissingCount - chart function NullCount NullCount - chart function NumericCount NumericCount - chart function TextCount TextCount - chart function Financial aggregation functions Financial aggregation functions in the data load script Financial aggregation functions in chart expressions IRR IRR - chart function NPV NPV - chart function

Script syntax and chart functions - Qlik Sense, 2.1.1

150 150 150 150 150 153 153 153 154 155 157 158 160 162 163 165 166 168 169 170 171 173 173 174 174 175 177 178 180 181 182 183 185 186 188 188 189 189 190 192 193

7

Contents XIRR XIRR - chart function XNPV XNPV - chart function Statistical aggregation functions Statistical aggregation functions in the data load script Statistical aggregation functions in chart expressions Avg Avg - chart function Correl Correl - chart function Fractile Fractile - chart function Kurtosis Kurtosis - chart function LINEST_B LINEST_B - chart function LINEST_DF LINEST_DF - chart function LINEST_F LINEST_F - chart function LINEST_M LINEST_M - chart function LINEST_R2 LINEST_R2 - chart function LINEST_SEB LINEST_SEB - chart function LINEST_SEM LINEST_SEM - chart function LINEST_SEY LINEST_SEY - chart function LINEST_SSREG LINEST_SSREG - chart function LINEST_SSRESID LINEST_SSRESID - chart function Median Median - chart function Skew Skew - chart function Stdev Stdev - chart function Sterr Sterr - chart function STEYX STEYX - chart function An example of how to use linest functions

Script syntax and chart functions - Qlik Sense, 2.1.1

195 196 197 198 199 199 202 205 206 208 209 211 212 214 215 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 240 241 243 244 246 247 249 250 252

8

Contents Loading the sample data Displaying the results from the data load script calculations Creating the linest chart function visualizations Statistical test functions Chi-2 test functions T-test functions Z-test functions Chi2-test functions Chi2Test_chi2 Chi2Test_df Chi2Test_p - chart function T-test functions TTest_conf TTest_df TTest_dif TTest_lower TTest_sig TTest_sterr TTest_t TTest_upper TTestw_conf TTestw_df TTestw_dif TTestw_lower TTestw_sig TTestw_sterr TTestw_t TTestw_upper TTest1_conf TTest1_df TTest1_dif TTest1_lower TTest1_sig TTest1_sterr TTest1_t TTest1_upper TTest1w_conf TTest1w_df TTest1w_dif TTest1w_lower TTest1w_sig TTest1w_sterr TTest1w_t TTest1w_upper Z-test functions ZTest_z

Script syntax and chart functions - Qlik Sense, 2.1.1

252 253 253 254 254 255 255 255 255 256 257 258 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 282 283 284 285 286 286 287 288 289 290 291 292 294

9

Contents ZTest_sig ZTest_dif ZTest_sterr ZTest_conf ZTest_lower ZTest_upper ZTestw_z ZTestw_sig ZTestw_dif ZTestw_sterr ZTestw_conf ZTestw_lower ZTestw_upper Statistical test function examples Examples of how to use chi2-test functions in charts Examples of how to use chi2-test functions in the data load script Creating a typical t-test report Examples of how to use z-test functions String aggregation functions String aggregation functions in the data load script String aggregation functions in charts Concat Concat - chart function FirstValue LastValue MaxString MaxString - chart function MinString MinString - chart function Synthetic dimension functions ValueList - chart function ValueLoop - chart function Nested aggregations Nested aggregations with the TOTAL qualifier 5.2 Color functions

294 295 296 297 298 299 300 301 301 302 303 304 305 306 306 309 310 313 315 316 316 317 318 320 321 322 323 325 326 327 328 329 330 331 331

Pre-defined color functions ARGB RGB HSL 5.3 Conditional functions

333 334 334 335 336

Conditional functions overview alt class if match

Script syntax and chart functions - Qlik Sense, 2.1.1

336 337 337 339 339

10

Contents mixmatch pick wildmatch 5.4 Counter functions

340 340 341 341

Counter functions overview autonumber autonumberhash128 autonumberhash256 IterNo RecNo RowNo RowNo - chart function 5.5 Date and time functions

341 342 345 347 349 350 351 352 354

Date and time functions overview Integer expressions of time Timestamp functions Make functions Other date functions Timezone functions Set time functions In... functions Start ... end functions Day numbering functions addmonths addyears age converttolocaltime day dayend daylightsaving dayname daynumberofquarter daynumberofyear daystart firstworkdate GMT hour inday indaytotime inlunarweek inlunarweektodate inmonth inmonths inmonthstodate inmonthtodate

Script syntax and chart functions - Qlik Sense, 2.1.1

354 354 356 356 356 357 357 357 359 362 363 363 364 365 368 368 369 370 371 372 373 375 376 376 377 378 380 381 383 384 387 388

11

Contents inquarter inquartertodate inweek inweektodate inyear inyeartodate lastworkdate localtime lunarweekend lunarweekname lunarweekstart makedate maketime makeweekdate minute month monthend monthname monthsend monthsname monthsstart monthstart networkdays now quarterend quartername quarterstart second setdateyear setdateyearmonth timezone today UTC week weekday weekend weekname weekstart weekyear year yearend yearname yearstart yeartodate 5.6 Exponential and logarithmic functions

390 391 392 394 396 398 400 401 402 404 406 407 408 408 409 409 410 411 413 414 416 418 419 421 422 423 426 427 428 429 430 430 431 431 432 433 435 437 439 440 440 442 444 446 447

5.7 Field functions

449

Script syntax and chart functions - Qlik Sense, 2.1.1

12

Contents Count functions Field and selection functions GetAlternativeCount - chart function GetCurrentSelections - chart function GetExcludedCount - chart function GetFieldSelections - chart function GetNotSelectedCount - chart function GetPossibleCount - chart function GetSelectedCount - chart function 5.8 File functions

449 449 450 451 452 453 455 455 456 457

File functions overview Attribute ConnectString FileBaseName FileDir FileExtension FileName FilePath FileSize FileTime GetFolderPath QvdCreateTime QvdFieldName QvdNoOfFields QvdNoOfRecords QvdTableName 5.9 Financial functions

457 459 467 467 467 468 468 468 469 470 470 471 472 472 473 474 475

Financial functions overview BlackAndSchole FV nPer Pmt PV Rate 5.10 Formatting functions

475 476 477 478 479 479 480 481

Formatting functions overview Date Dual Interval Money Num Time Timestamp 5.11 General numeric functions

481 483 483 485 486 487 487 488 489

General numeric functions overview

Script syntax and chart functions - Qlik Sense, 2.1.1

489

13

Contents Combination and permutation functions Modulo functions Parity functions Rounding functions BitCount Ceil Combin Div Even Fabs Fact Floor Fmod Frac Mod Odd Permut Round Sign 5.12 Geospatial functions

490 490 490 491 491 492 492 493 493 494 494 495 495 496 496 497 497 498 498 499

Geospatial functions overview GeoAggrGeometry GeoBoundingBox GeoCountVertex GeoGetBoundingBox GeoGetPolygonCenter GeoInvProjectGeometry GeoMakePoint GeoProject GeoProjectGeometry GeoReduceGeometry 5.13 Interpretation functions

499 500 501 502 502 503 503 504 504 505 506 506

Interpretation functions overview Date# Interval# Money# Num# Text Time# Timestamp# 5.14 Inter-record functions

507 508 508 509 510 511 512 512 513

Row functions Column functions Field functions Pivot table functions

Script syntax and chart functions - Qlik Sense, 2.1.1

513 514 515 515

14

Contents Inter-record functions in the data load script Above - chart function Below - chart function Bottom - chart function Column - chart function Dimensionality - chart function Exists FieldIndex FieldValue FieldValueCount LookUp NoOfRows - chart function Peek Previous Top - chart function Secondarydimensionality After - chart function Before - chart function First - chart function Last - chart function ColumnNo - chart function NoOfColumns - chart function 5.15 Logical functions

516 517 521 525 529 531 531 533 535 536 538 539 540 543 544 548 548 549 550 551 552 553 553

5.16 Mapping functions

554

Mapping functions overview ApplyMap MapSubstring 5.17 Mathematical functions

554 554 556 557

5.18 NULL functions

558

NULL functions overview IsNull NULL 5.19 Range functions

558 559 559 560

Basic range functions Counter range functions Statistical range functions Financial range functions RangeAvg RangeCorrel RangeCount RangeFractile RangeIRR RangeKurtosis RangeMax RangeMaxString

Script syntax and chart functions - Qlik Sense, 2.1.1

561 561 562 563 563 565 567 569 571 572 573 575

15

Contents RangeMin RangeMinString RangeMissingCount RangeMode RangeNPV RangeNullCount RangeNumericCount RangeOnly RangeSkew RangeStdev RangeSum RangeTextCount RangeXIRR RangeXNPV 5.20 Ranking functions in charts

576 578 580 581 583 584 586 587 588 589 590 592 594 595 596

Rank - chart function HRank - chart function 5.21 Statistical distribution functions

597 600 601

Statistical distribution functions overview CHIDIST CHIINV FDIST FINV NORMDIST NORMINV TDIST TINV 5.22 String functions

602 603 603 604 605 605 606 607 607 608

String functions overview Capitalize Chr Evaluate FindOneOf Hash128 Hash160 Hash256 Index KeepChar Left Len Lower LTrim Mid Ord PurgeChar

Script syntax and chart functions - Qlik Sense, 2.1.1

608 611 612 612 612 613 613 614 614 615 616 616 616 617 617 618 618

16

Contents Repeat Replace Right RTrim SubField SubStringCount TextBetween Trim Upper 5.23 System functions

619 619 620 621 621 623 624 624 625 625

System functions overview GetObjectField - chart function IsPartialReload ProductVersion StateName - chart function 5.24 Table functions

625 627 627 628 628 628

Table functions overview FieldName FieldNumber NoOfFields NoOfRows 5.25 Trigonometric and hyperbolic functions

628 630 631 631 632 632

6 File system access restriction

635

Security aspects when connecting to file based ODBC and OLE DB data connections 6.1 Limitations in standard mode

635 635

System variables Regular script statements Script control statements File functions System functions 6.2 Disabling standard mode

635 637 638 638 640 640

Qlik Sense Qlik Sense Desktop 7 QlikView functions and statements not supported in Qlik Sense

640 640 642

7.1 Script statements not supported in Qlik Sense

642

7.2 Functions not supported in Qlik Sense

642

8 Functions and statements not recommended in Qlik Sense

643

8.1 Script statements not recommended in Qlik Sense

643

8.2 Script statement parameters not recommended in Qlik Sense

643

8.3 Functions not recommended in Qlik Sense

644

ALL qualifier

Script syntax and chart functions - Qlik Sense, 2.1.1

645

17

1   What is Qlik Sense?

1

What is Qlik Sense?

Qlik Sense is a platform for data analysis. With Qlik Sense you can analyze data and make data discoveries on your own. You can share knowledge and analyze data in groups and across organizations. Qlik Sense lets you ask and answer your own questions and follow your own paths to insight. Qlik Sense enables you and your colleagues to reach decisions collaboratively.

1.1

What can you do in Qlik Sense?

Most Business Intelligence (BI) products can help you answer questions that are understood in advance. But what about your follow-up questions? The ones that come after someone reads your report or sees your visualization? With the Qlik Sense associative experience, you can answer question after question after question, moving along your own path to insight. With Qlik Sense you can explore your data freely, with just clicks, learning at each step along the way and coming up with next steps based on earlier findings.

1.2

How does Qlik Sense work?

Qlik Sense generates views of information on the fly for you. Qlik Sense does not require predefined and static reports or you being dependent on other users – you just click and learn. Every time you click, Qlik Sense instantly responds, updating every Qlik Sense visualization and view in the app with a newly calculated set of data and visualizations specific to your selections.

The app model Instead of deploying and managing huge business applications, you can create your own Qlik Sense apps that you can reuse, modify and share with others. The app model helps you ask and answer the next question on your own, without having to go back to an expert for a new report or visualization.

The associative experience Qlik Sense automatically manages all the relationships in the data and presents information to you using a green/white/gray metaphor. Selections are highlighted in green, associated data is represented in white, and excluded (unassociated) data appears in gray. This instant feedback enables you to think of new questions and continue to explore and discover.

Collaboration and mobility Qlik Sense further enables you to collaborate with colleagues no matter when and where they are located. All Qlik Sense capabilities, including the associative experience and collaboration, are available on mobile devices. With Qlik Sense, you can ask and answer your questions and follow-up questions, with your colleagues, wherever you are.

1.3

How can you deploy Qlik Sense?

There are two versions of Qlik Sense to deploy, Qlik Sense Desktop and Qlik Sense Server.

Script syntax and chart functions - Qlik Sense, 2.1.1

18

1   What is Qlik Sense? Qlik Sense Desktop This is an easy-to-install single user version that is typically installed on a local computer.

Qlik Sense Server This version is used to deploy Qlik Sense sites. A site is a collection of one or more server machines connected to a common logical repository or central node.

1.4

How to administer and manage a Qlik Sense site

With the Qlik Management Console you can configure, manage and monitor Qlik Sense sites in an easy and intuitive way. You can manage licenses, access and security rules, configure nodes and data source connections and synchronize content and users among many other activities and resources.

1.5

Extend Qlik Sense and adapt it for your own purposes

Qlik Sense provides you with flexible APIs and SDKs to develop your own extensions and adapt and integrate Qlik Sense for different purposes, such as:

Building extensions and mashups Here you can do web development using JavaScript to build extensions that are custom visualization in Qlik Sense apps, or you use a mashups APIs to build websites with Qlik Sense content.

Building clients You can build clients in .NET and embed Qlik Sense objects in your own applications. You can also build native clients in any programming language that can handle WebSocket communication by using the Qlik Sense client protocol.

Building server tools With service and user directory APIs you can build your own tool to administer and manage Qlik Sense sites.

Connecting to other data sources Create Qlik Sense connectors to retrieve data from custom data sources.

Script syntax and chart functions - Qlik Sense, 2.1.1

19

2   Script syntax

2

Script syntax

2.1

Introduction to script syntax

In the script, the name of the data source, the names of the tables and the names of the fields included in the logic are defined. Furthermore, the fields in the access rights definition are defined in the script. The script consists of a number of statements that are executed consecutively. The Qlik Sense command line syntax and script syntax are described in a notation called Backus-Naur Formalism, or BNF code. The first lines of code are already generated when a new Qlik Sense file is created. The default values of these number interpretation variables are derived from the regional settings of the OS. In the script the name of the data source, the names of the tables and the names of the fields included in the logic are defined. The script consists of a number of script statements and keywords that are executed consecutively. For a table file with commas, tabs or semicolons as delimiter, the LOAD-statement may be used. By default the LOAD-statement will load all fields of the file. A general database must be accessed through Microsoft ODBC. Here standard SQL statements are used. The SQL syntax accepted differs between different ODBC drivers. All script statements must end with a semicolon, " ;". A detailed description of script syntax can be accessed via the topics in this section.

2.2

What is Backus-Naur formalism?

The Qlik Sense command line syntax and script syntax are described in a notation called Backus-Naur formalism, also known as BNF code. The following table provides a list of symbols used in BNF code, with a description of how they are interpreted:

|

Logical OR: the symbol on either side can be used.

()

Parentheses defining precedence: used for structuring the BNF syntax.

[]

Square brackets: enclosed items are optional.

{}

Braces: enclosed items may be repeated zero or more times.

Symbol

A non-terminal syntactic category, that: can be divided further into other symbols. For example, compounds of the above, other non-terminal symbols, text strings, and so on.

::=

Marks the beginning of a block that defines a symbol.

LOAD

A terminal symbol consisting of a text string. Should be written as it is into the script.

Script syntax and chart functions - Qlik Sense, 2.1.1

20

2   Script syntax All terminal symbols are printed in a bold face font. For example, "(" should be interpreted as a parenthesis defining precedence, whereas " (" should be interpreted as a character to be printed in the script.

Example: The description of the alias statement is:

alias fieldname as aliasname { , fieldname as aliasname} This should be interpreted as the text string "alias", followed by an arbitrary field name, followed by the text string "as", followed by an arbitrary alias name. Any number of additional combinations of "fieldname as alias" may be given, separated by commas. The following statements are correct: alias a as first; alias a as first, b as second; alias a as first, b as second, c as third;

The following statements are not correct: alias a as first b as second; alias a as first { , b as second };

2.3

Script statements and keywords

The Qlik Sense script consists of a number of statements. A statement can be either a regular script statement or a script control statement. Certain statements can be preceded by prefixes. Regular statements are typically used for manipulating data in one way or another. These statements may be written over any number of lines in the script and must always be terminated by a semicolon, ";". Control statements are typically used for controlling the flow of the script execution. Each clause of a control statement must be kept inside one script line and may be terminated by a semicolon or the end-of-line. Prefixes may be applied to applicable regular statements but never to control statements. The when and

unless prefixes can however be used as suffixes to a few specific control statement clauses. In the next subchapter, an alphabetical listing of all script statements, control statements and prefixes, are found. All script keywords can be typed with any combination of lower case and upper case characters. Field and variable names used in the statements are however case sensitive.

Script control statements The Qlik Sense script consists of a number of statements. A statement can be either a regular script statement or a script control statement. Control statements are typically used for controlling the flow of the script execution. Each clause of a control statement must be kept inside one script line and may be terminated by semicolon or end-of-line.

Script syntax and chart functions - Qlik Sense, 2.1.1

21

2   Script syntax Prefixes are never applied to control statements, with the exceptions of the prefixes when and unless which may be used with a few specific control statements. All script keywords can be typed with any combination of lower case and upper case characters.

Script control statements overview Each function is described further after the overview. You can also click the function name in the syntax to immediately access the details for that specific function.

Call The call control statement calls a subroutine which must be defined by a previous sub statement.

Call name ( [ paramlist ]) Do..loop The do..loop control statement is a script iteration construct which executes one or several statements until a logical condition is met.

Do..loop [ ( while | until ) condition ] [statements] [exit do [ ( when | unless ) condition ] [statements] loop [ ( while | until ) condition ] Exit script This control statement stops script execution. It may be inserted anywhere in the script.

Exit script[ (when | unless) condition ] For each ..next The for each..next control statement is a script iteration construct which executes one or several statements for each value in a comma separated list. The statements inside the loop enclosed by for and next will be executed for each value of the list.

For each..next var in list [statements] [exit for [ ( when | unless ) condition ] [statements] next [var] For..next The for..next control statement is a script iteration construct with a counter. The statements inside the loop enclosed by for and next will be executed for each value of the counter variable between specified low and high limits.

For..next counter = expr1 to expr2 [ stepexpr3 ] [statements] [exit for [ ( when | unless ) condition ] [statements] Next [counter]

Script syntax and chart functions - Qlik Sense, 2.1.1

22

2   Script syntax If..then The if..then control statement is a script selection construct forcing the script execution to follow different paths depending on one or several logical conditions.

Since the if..then statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary. If..then..elseif..else..end if condition then [ statements ] { elseif condition then [ statements ] } [ else [ statements ] ] end if Sub The sub..end sub control statement defines a subroutine which can be called upon from a call statement.

Sub..end sub name [ ( paramlist )] statements end sub Switch The switch control statement is a script selection construct forcing the script execution to follow different paths, depending on the value of an expression.

Switch..case..default..end switch expression {case valuelist [ statements ]} [default statements] end switch

Call The call control statement calls a subroutine which must be defined by a previous sub statement.

Syntax: Call name ( [ paramlist ])

Arguments: Argument

Description

name

The name of the subroutine.

paramlist

A comma separated list of the actual parameters to be sent to the subroutine. Each item in the list may be a field name, a variable or an arbitrary expression.

Script syntax and chart functions - Qlik Sense, 2.1.1

23

2   Script syntax The subroutine called by a call statement must be defined by a sub encountered earlier during script execution. Parameters are copied into the subroutine and, if the parameter in the call statement is a variable and not an expression, copied back out again upon exiting the subroutine.

Limitations: Since the call statement is a control statement and as such is ended with either a semicolon or end-of-line, it must not cross a line boundary.

Example 1: // Example 1 Sub INCR (I,J) I = I + 1 Exit Sub when I < 10 J = J + 1 End Sub Call INCR (X,Y)

Example 2: // Example 2 - List all QV related files on disk sub DoDir (Root) For Each Ext in 'qvw', 'qvo', 'qvs', 'qvt', 'qvd', 'qvc', 'qvf' For Each File in filelist (Root&'\*.' &Ext) LOAD '$(File)' as Name, FileSize( '$(File)' ) as Size, FileTime( '$(File)' ) as FileTime autogenerate 1; Next File Next Ext For Each Dir in dirlist (Root&'\*' ) Call DoDir (Dir) Next Dir End Sub Call DoDir ('C:')

Do..loop The do..loop control statement is a script iteration construct which executes one or several statements until a logical condition is met.

Syntax:

Script syntax and chart functions - Qlik Sense, 2.1.1

24

2   Script syntax Do [ ( while | until ) condition ] [statements] [exit do [ ( when | unless ) condition ] [statements] loop[ ( while | until ) condition ]

Since the do..loop statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its three possible clauses (do, exit do and loop) must not cross a line boundary.

Arguments: Argument

Description

condition

A logical expression evaluating to True or False.

statements

Any group of one or more Qlik Sense script statements.

while / until

The while or until conditional clause must only appear once in any do..loop statement, i.e. either after do or after loop. Each condition is interpreted only the first time it is encountered but is evaluated for every time it encountered in the loop.

exit do

If an exit do clause is encountered inside the loop, the execution of the script will be transferred to the first statement after the loop clause denoting the end of the loop. An exit

do clause can be made conditional by the optional use of a when or unless suffix. Example: // LOAD files file1.csv..file9.csv Set a=1; Do while a, >=,
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF