forked from ChristofSchwarz/QlikScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-prev-buttons.txt
90 lines (73 loc) · 4.53 KB
/
next-prev-buttons.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
TRACE including https://github.com/ChristofSchwarz/QlikScripts/blob/master/next-prev-buttons.txt;
TRACE Version 1.0;
SUB CreatePrevNextVar(paramField, paramType, paramPrecision)
/*
Author: Christof Schwarz
Version: 1.0 - 04-SEP-2021
This sub will create 4 variables for a given fieldname (provided in paramField). The
paramType is one of the following (case-insensitive):
Txt or Text, Int or Integer, Num or Numeric, Dual, Date, DateTime or Timestamp
The optional 3rd parameter is Precision and is needed for numeric values with decimals
(a timestamp for example has up to 9 digits after the decimal sign!) and it defines how
many digits after the decimal need to be identical for a match (e.g. 1e-8 or 1e-9).
The 3rd parameter will get an intelligent default if you don't provide it.
Examples:
For a text field you'd CALL CreatePrevNextVar('ProductCategory', 'Text')
and you get 4 variables:
[vNext:ProductCategory] ... a search string for the [Next] Action Button
[vPrev:ProductCategory] ... a search string for the [Prev] Action Button
[vNextVal:ProductCategory] ... a text with the next value after the current
[vPrevVal:ProductCategory] ... a text with the previous value after the current
For a timestamp field you'd CALL CreatePrevNextVar('CreationDateTime', 'timestamp')
and you get 4 variables:
[vNext:CreationDateTime] ... a search string for the [Next] Action Button
[vPrev:CreationDateTime] ... a search string for the [Prev] Action Button
[vNextVal:CreationDateTime] ... a text with the next value after the current
[vPrevVal:CreationDateTime] ... a text with the previous value after the current
*/
// Get an intelligent default for privPrecision, if paramPrecision was omitted
IF '$(paramPrecision)' = '' THEN
IF Wildmatch(paramType, 'Datetime','Timestamp') THEN
LET privPrecision = Num(1/24/3600/1000/2, '', '.', ' ');
ELSEIF Wildmatch(paramType, 'Num*') THEN
SET privPrecision = 1E-9;
ELSE
LET privPrecision = 0;
END IF
ELSE
LET privPrecision = Num(Alt('$(paramPrecision)', 0), '', '.', ' ');
END IF
TRACE `SUB CreatePrevNextVar('$(paramField)', '$(paramType)', $(privPrecision))`;
// Create Next Value and Prev Value variables
LET [vNextVal:$(paramField)] = 'If(IsNull([$(paramField)]), MinString([$(paramField)]),
MinString(TOTAL {<[$(paramField)]={"=Only({<[$(paramField)]=>}[$(paramField)]) > Only(TOTAL [$(paramField)])"}>} [$(paramField)])
)';
LET [vPrevVal:$(paramField)] = 'If(IsNull([$(paramField)]), MaxString([$(paramField)]),
MaxString(TOTAL {<[$(paramField)]={"=Only({<[$(paramField)]=>}[$(paramField)]) < Only(TOTAL [$(paramField)])"}>} [$(paramField)])
)';
// Create the search strings for the Next and Prev Action Buttons based on the type
IF paramType LIKE 'T*xt' THEN
LET [vNext:$(paramField)] = CHR(39) & '=Only({<[$(paramField)]=>}[$(paramField)])=''''$' & '(=' & [vNextVal:$(paramField)] & ')''''' & CHR(39);
LET [vPrev:$(paramField)] = CHR(39) & '=Only({<[$(paramField)]=>}[$(paramField)])=''''$' & '(=' & [vPrevVal:$(paramField)] & ')''''' & CHR(39); ;
LET privPrecision = Null();
ELSEIF Wildmatch(paramType, 'Num*', 'Int*', 'Dual', 'Date', 'Datetime', 'Timestamp') THEN
LET [vNext:$(paramField)] = 'Num(If(IsNull([$(paramField)]), Min([$(paramField)]),
Min(TOTAL {<[$(paramField)]={"=Only({<[$(paramField)]=>}[$(paramField)]) > Only(TOTAL [$(paramField)])"}>} [$(paramField)])
),'''',''.'','' '')';
LET [vPrev:$(paramField)] = 'Num(If(IsNull([$(paramField)]), Max([$(paramField)]),
Max(TOTAL {<[$(paramField)]={"=Only({<[$(paramField)]=>}[$(paramField)]) < Only(TOTAL [$(paramField)])"}>} [$(paramField)])
),'''',''.'','' '')';
IF privPrecision = 0 THEN
LET [vNext:$(paramField)] = CHR(39) & '=Only({<[$(paramField)]=>}[$(paramField)]) = $' & '(=' & [vNext:$(paramField)] & ')' & CHR(39);
LET [vPrev:$(paramField)] = CHR(39) & '=Only({<[$(paramField)]=>}[$(paramField)]) = $' & '(=' & [vPrev:$(paramField)] & ')' & CHR(39);
ELSE
LET [vNext:$(paramField)] = CHR(39) & '=FAbs(Only({<[$(paramField)]=>}[$(paramField)]) - $' & '(=' & [vNext:$(paramField)] & ')) < ' & privPrecision & CHR(39);
LET [vPrev:$(paramField)] = CHR(39) & '=FAbs(Only({<[$(paramField)]=>}[$(paramField)]) - $' & '(=' & [vPrev:$(paramField)] & ')) < ' & privPrecision & CHR(39);
END IF
LET privPrecision = Null();
ELSE
LET privPrecision = Null();
// Throw error
[SUB CreatePrevNextVar: Unknown Field type "$(paramType)"];
END IF
END SUB