Showing posts with label qlikview. Show all posts
Showing posts with label qlikview. Show all posts

Friday, September 29, 2017

QV30 Qlikview Interview Questions

Qlikview is powerful BI tool used to create report, dashboards and this tool is capable of showing real time report or snapshot based reports.

Real time report - data is directly coming from OLTP database
Snapshot reports - Qlikview collect data in QVD's, which needs to refresh on daily/weekly basis

Below are the some of qlikview questions which can be asked by any interviewer.

QlikView Interview Questions:


QlikView Architecture:
1. Optimized and Un-optimized QVD Load Situations?
2. 3 tier architecture implementation
3. How does QlikView stores data internally?
4. Restrictions of Binary Load?
5. How are NULLS implemented in QlikView?
6. How do you optimize QlikView Application? (What tools are used and where do you start?)
7. What is the difference between Subset ratio & Information Density?

QlikView Scripting:
1. What is the difference between ODBC, OLEDB & JDBC?
2. What is the use of Crosstable prefix in QlikView Load Script?
3. What is Mapping Load & ApplyMap()?
4. What is the difference between Map Using and Mapping Load?
5. Synthetic keys in QlikView and how & when to avoid them?
6. Difference types of Joins in QlikView?
7. What is the difference between Join and Keep?
8. How do you use Having clause (SQL Equivalent) along with Group By in QlikView?
9. Explain IntervalMatch function in QlikView?
10.Explain Concatenation, No Concatenation & Auto Concatenation?
11.Explain how to implement Incremental Load?
12.What is Circular Loop and how do you avoid it?
13.Explain Exists() function in QlikView and when do you use this function?
14.What is Generic Load in QlikView?

QlikView Expression Language / UI:
1. Explain Aggr Function?
2. What is the use of FirstSortValue in QlikView?
3. What are Set Modifiers and Set Identifiers?
4. What is P() & E() and where do you use them?
5. What is the difference between ValueList() and ValueLoop()?
6. What is Partial Reload? Why do you use “ONLY” Qualifier?
7. Difference between Cyclic Group & Drilldown Group?
8. Explain Alternate States? Where do you use them?

QlikView Security:
1. Describe Section Access Architecture?
2. Difference between Authentication & Authorization in QlikView? How to implement them?
3. Difference between File System Security vs Section Access?
4. Explain “Strict Exclusion” while implementing Section Access? What are the implications of not using them?
5. How do you implement Section Access on hierarchy based data?


QlikView Server and Publisher:
1. What are the multiple protocols defined for client communication with QVS?
2. Explain different communication encryptions for Windows Client & AJAX Client?
3. What is the use of Anonymous User Account in QVS?
4. What are the different types of CALS and Explain them?
5. What are the different editions of QlikView Server?

General:

1. Difference between RDBMS and Associative Database?
2. Ragged hierarchies in Data Ware Housing?
3. Explain EAV data Modelling Technique?
4 What are slowly changing dimensions?



Questions About Roles

1. Whats your role in your project
2. Whats your daily activity in your project
3. Requirement Gathering
4. One can ask About your project
5. What is the major KPI s in your project
6. What is Dashboard
7. Which  architecture are you using in your project
8. What type of schema are you using in your project
9. Difference between Star and Snowflake schema
10. What is Peek, Previous, Apply map, Interval Match
11. Whats is the difference between Pick and Match
12. What is Fuzzy search
13. How many charts are you used till now
14. Have you used macros in your project and why
15. Whats the difference between QV versions
16. Have you used Alternate states and why
17. How many dimensions are used in Guage Chart
18. What is set analysis
19. Best data modelling techniques
20. You have any knowledge about QV server and Publisher
21. What is Incremental Load
22. Have you Create Ad-hoc reports in your project And how
23. Any knowledge about Data Island
24. DMS authorization
24. Section Access
25. Conditional enabling
26. Difference between join and keep
27. Difference between Concatenate and join
28. Binary Load, Preceding Load, Partial Load
29. How many ways you can maintain to store the QVD's

1. Qlikview features
2. What is Circular loops
3. What is Synthetic key, is it good or bad having?
4. What P() and E() in Set analysis?
5. What is Comparative analysis?
6. What is Mekko chart and what is the difference between bar and Mekko chart?
7. What is the difference between Pivot, Straight and Table box?
8. How you connect to Database?
9. What are the various data sources for Qlikview?
10. What is partial reloading?
11. How you refresh you dashboards periodically?
12. What are the different types of CALs available?
13. What are the various joins available in Qlikview?
14. How you use Macros in Qlikview?
15. How you optimize Qlikview dashboards?
16. What care should be taken while designing a datamodel?
17. How you test your Dashboard?
18. Types of authorization in Qlikview?
19. Difference between Join and Concatenate?
20. What is NoConcatenate?

Tuesday, April 14, 2015

QV29 Find and replace in all expression and conditions

If you have create a variable and try to add one by one in all charts, so dont waste your time.
We have find and replace functionality in qlikview  thru this we can replace a word in whole document.

goto MENU - setting - Expression Overview
or
ctrl +alt +e



QV28 Hidden sheets and objects in QLikkview

In qlikview document we can hide the sheets and sheet object. Hide means these will not visible to user any more, untill unless he enable them.

How to identify whether hidden sheet and objects are present in document:
goto MENU - setting - Expression Overview
or
ctrl +alt +e

LOOK the picture below, i have highlighted the sheet name (in yellow color) showing null value. which means we have hidden sheet in the document.


How to unhide sheet and object:
way1 - we can over ride the settings by pressing ctrl+alt+s
note*-Be very careful to undo this change before moving your application into a production environment.

way2: go to Menu - setting - Document Properties - sheet (tab)
look onto the STATUS column (Normal | Conditional: hidden | Conditional: Normal)
select any one sheet and properties - Under General tab - remove conditions

How to hide the document or sheet:
Write the condition 1=0 (under general tab of sheet and chart properties both)

Friday, March 20, 2015

QV27 Checklist for a good qlikview developer

If you are good qlikview developer, and like to work in steps, or good planed work. Then you should have some points in your mind - that should meet with your code.

This can lead to good product and code quality.

Data Model Performance
  1. Synthetic keys removed from data model   
  2. Ambiguous loops removed from data model   
  3. Correct granularity of data   
  4. Use of QVDs where possible   
  5. Use integers to join tables where possible   
  6. Remove system keys/timestamps from data model   
  7. Unused fields removed from data model   
  8. Remove link tables from very large data models   
  9. Remove unneeded snowflaked tables (consolidate)   
  10. Break concatenated dim. fields into distinct fields    
  11. All QVD reads optimized   
  12. Use Autonumber to replace large concatenated keys   

Interface Performance
  1. Run QlikView Optimizer to test memory usage   
  2. Minimize count distinct functions   
  3. Minimize nested Ifs   
  4. Minimize string comparisons   
  5. Macros minimized or eliminated   
  6. Minimize Show Frequency feature   
  7. Minimize open objects on sheet   
  8. Minimize set analysis against large fact tables   
  9. Minimize pivot charts in very large apps   
  10. Avoid "Show Frequency" feature on large data   
  11. Avoid AGGR function when possible   
  12. Avoid IF statements in calculated chart dimensions   
  13. Avoid built-in time functions in GUI (inmonth, etc…)   


Design Best Practices                       
  1. Use of colors for contrast/focus only               
  2. Use of neutral and muted colors                
  3. Use of templates/themes where available               
  4. Display optimized for user screen resolutions               
  5. Design consistency across tabs               
  6. Formatting consistency across objects               
  7. Most used selections at top - least at bottom               
  8. Drop-down selections on all straight/pivot table columns               
  9. Developer QV version matches production               
  10. Test client types for rendering               
  11. Use of Common Variables for expressions               
  12. Use calculation conditions on large charts                
                       
Script Best Practices          
  1. Naming standards used for columns, tables, variables               
  2. Script is well commented - changes date flagged               
  3. First tab holds information section               
  4. Subject areas each have tab in script               
  5. Use of Include files or hidden script for all ODBC connections               
  6. All code blocks with comment sections               
  7. All file references using UNC naming               
  8. Business names for UI fields               
  9. Security script in Inlcude file               
  10. Turn Generate Logfile option on               
  11. UPPER() function used on Section Access fields               
  12. Publisher Service Acct added to Section Access               
  13. Use numeric flags where possible               


Thursday, March 19, 2015

QV26 Naming convention for any qlikview project

Prefixes                               
variables                Starts with a "v"             e.g.    vYear       
Key Fields               Starts with a "%"             e.g.    %companykey       
Flag Fields              Starts with a "_"             e.g.    _IsEnable       
Cycle Group              Starts with a "<"          e.g.    <YearMonth
Drilldown Group          Starts with a ">"          e.g.    >CountryStateCity
Key Field Separator      Separated by "_"              e.g.    Company&'_'&Nbr as Key       
Temp Fileds/Tables       End With "_tmp"               e.g.    Daily_Trans_tmp       

                                   
Field Names                               
Use business names for fields.                       e.g.    Customer Nbr instead of CustNo       
Rename fields in scripts where possible - not in charts and tables                                
                                   
Publisher Naming Standards                               
Abbr.  Abbr. Type     Meaning                       
All    Environment    Applicable to all environments                       
DEV    Environment    Development Environment                       
PRD    Environment    Production Environment                       
TST    Environment    Test Environment                       
APR    Publisher Item    Publisher Access Point Resource                       
JOB    Publisher Item    Publisher Job                       
SDF    Publisher Item    Publisher Source Document Folder Resource                       
TSK    Publisher Item    Publisher task                       
DSR    Publisher Item    Directory Service Resource                       
                                   

QV25 How to tune a qlikview application

We know that Qlikview is data pulling and other operations are quite faster than other tools. Still we need to optimize the qlikview document.

Reload, chart loading are depend upon various factor. Good data model also leads to high speed.

Some below factor we need to take care in document:



Reduce Rows
Eliminate unneeded data volume (rows) from apps (how far back does the app really need to store data?
Reduce Columns
Find unused fields in the data model - use DocumentAnalyzer_V1.5.qvw against your app to do this, then copy the "DROP FIELD" statements that are generated for the unused fields and place these into a new tab in YOUR application, as the VERY LAST tab in the script. 
Reduce Distinctness
Reduce Distinctness - Reduce distinct values in your application - use the QlikView Optimizer.qvw against your app to find the fields that are candidates for these changes.   Select the "Symbols" in the Optimizer app to see these (timestamps, system keys, etc..)
Increase efficiency
Convert fields to numeric that are used in compare expressions, like IF(ClientType = 'Direct'….)
Reduce data model complexity
Collapse snowlfaked tables to attain a more pure star schema   
Reduce App complexity
Reduce number of tabs/objects in the application, where appropriate
Reduce App complexity
Reduce the number of open charts down to 1 on tabs where this is possible and appropriate
Best Practices
Follow checklist items above in all areas


For Charts
1. Avoid Calculated dimensions - if possible use direct column in dimensions, calculated dimension leads to decrease the performance of table chart, because calculated dimension, do calculation for every row.


Wednesday, March 18, 2015

QV24 button - action "Toggle Select"

In script, we have Inline table, which contain field one, on which we are going to apply toggle to filter data from reports.

load * inline [
one, data
1,j
1,4
1,info
1,blog
0,spot
0,com
];

now create a sheet object- " button"
    - properties
    - Actions
    - add action
    - "Toggle select" (in field add field "one" and value in input box below field)
   


now add object on sheet "current select "
add object table box, add both fields in it.

now click on the button and see the behaviour in "chart" and "current selection box".

by default in table box it will show all rows including 1,0 . when we switch to toggle button it will show only 1 respective data in table box.
   


Wednesday, March 11, 2015

QV23 keepchar & purgechar in qlikview

replace equivalent in qlikview:

Want to remove unwanted chars from string?
Qlikview provide us very simple function like "keepchar" and "purgechar".

Keepchar - it will return only string, which we want to keep (we need to mention list of char, that we want to keep)
purgechar - it will remove unwanted chars from string (we need to mention list to char, that we dont want to keep)


examples:
=keepchar ( 'j%4in'(fo!','abcdefghijklmnopqrstuvwxyz0123456789' ) returns 'j4info'
=PurgeChar('j%4in'(fo!', '%(!' &chr(39))


*chr(39) - is used for remove single quote from string.

Friday, February 13, 2015

QV22 Script error code in Qlikview

Scripterror code are generally used to handle script error i.e. error handling in qlikview.

This variable will be reset to 0 after each successfully executed script statement. If an error occurs it will be set to an internal QlikView error code. Error codes are dual values with a numeric and a text component.
 
  • No error (Script Error =0)
  • General error (Script Error =1)
  • Syntax error (Script Error =2)
  • General ODBC error (Script Error =3)
  • General OLE DB error (Script Error =4)
  • General custom database error (Script Error =5)
  • General XML error (Script Error =6)
  • General HTML error (Script Error =7)
  • File not found (Script Error =8)
  • Database not found (Script Error =9)
  • Table not found (Script Error =10)
  • Field not found (Script Error =11)
  • File has wrong format (Script Error =12)
  • BIFF error (Script Error =13)
  • BIFF error encrypted (Script Error =14)
  • BIFF error unsupported version (Script Error =15)
  • Semantic error (Script Error =16)

Documentation
http://community.qlik.com/docs/DOC-5342

Example:
Check column existence in table 

Thursday, February 12, 2015

QV21 Check column existence in table

If you need to check the column exists in table ( qlikview table , resident table or any other type of load), use below code to check column existence. 


tab1:
load * inline [
sno, deleted
1,y
2,y
3,n
4,n
];

ErrorMode=0;          // continue running on errors
LOAD
  deleted,
  rowno() as row
  RESIDENT tab1: where row=1;
IF ScritpError=11 THEN
  // field doesnt exist
  TRACE field 'deleted' does not exist ;
ELSE
  // field exists
  TRACE field 'deleted'  exist;
ENDIF
ErrorMode=1;          // restore deafult error mode


or

ErrorMode=0;          // continue running on errors
LOAD
  deleted,
  rowno() as row
  RESIDENT tab1: where row=1;
IF ScriptErrorCount >= 1 THEN
  // field doesnt exist
  TRACE field 'deleted' does not exist ;
ELSE
  // field exists
  TRACE field 'deleted'  exist;
ENDIF
ErrorMode=1;          // restore deafult error mode

Tuesday, November 4, 2014

QV20 Filter the null values of column in set analysis

I have SCOTT.EMP table with us, and want to filter out null values .
the basic requirement is to filter the data using set analysis whose MGR is null.

Dimension - MGR
expression - SUM (SAL)



Now i want to remove null's from dimension of chart (i.e. sum= 5000 where MGR is null),
i can do in various ways but i want to use using "set analysis"


expression - sum({<MGR-={'=Len(Trim(MGR))=0'} >} [SAL])

QV19 Replace all null values

Null values in database can lead a big problem while calculating the dimensions.
In other word we can say that it is not good if database having null values in it.

It is good if we remove all null values. in Qlikview You can set a variable which will replace all null value with some string.

In very start of script/ Main tab of your document you need to add

NullAsValue *;
Set NullValue = 'NULL' ;

and then reload the document.

Below is the image will show data behaviour "COMM" column before and after adding variable.

Thursday, October 30, 2014

QV18 Duplicate values in dimension

Duplicate values in dimensions:




produce issue:
create table region (area varchar2(30), district varchar2(30), city varchar2(30));
insert into region values ('chandigarh', 'chandigarh', 'chandigarh');
insert into region values ('punjab', 'patiala', 'patiala');
insert into region values ('punjab', 'patiala', 'nabha');
insert into region values ('punjab', 'patiala', 'SAN');
insert into region values ('punjab', 'SAS', 'SAS');
insert into region values ('punjab', 'SAS', 'ZRK');


i added all column area , district, and city in dimension of PIVOT table
in city i have repeated values same reside in DISTRICT

and these repeated/duplicate values cause a bad result in the end.





The city in red box is extra and some time leads to trouble depend upon the expression. In simple words if i say, i dont want to see the repeated city name "patiala" in city column.


Where patiala is act as city as well as district.

We can fix this in two ways:
- at script level
- at chart level

AT SCRIPT level

at script level my table look like this




After modification in script it look like this:


use below script for above approach:
REG:
LOAD AREA,
    DISTRICT,
    if(CITY = DISTRICT,null(),CITY) as CITY;
SQL SELECT *
FROM SCOTT.REGION;



AT CHART level









Sunday, October 5, 2014

QV17 Subtract number from variable - set analysis expression

some times we need to subtract or add the number from the variable value. So i am posting this how we can subtract the number from set analysis expression in qlikview.

from this post we can learn
- how to use variable in set analysis
- how to subtract number from variable

Let have a look upon the matter
I have emp table and if you see the hiredate year variation from 1980 to 1987 as you can see in your below image.


I also have created calendar as in post 

after creation of calendar we have below data model.



After reload we have added below objects in the existing sheet. 

current selection is 1981 and variable vMaxYear store 1981 value in it. chart have below dimension
DEPTNO
HIREDATE

and expression :
chart1 - Sum ({$(=$(vMaxYear)-1)}>}SAL)
 will show the data of employees whose HIREDATE lie in the year 1980.

chart2 - Sum ({}SAL)
 will show all data, irrespective of any date selection.




Wednesday, September 17, 2014

QV16 Create calendar dimension using min max date

In this post i have created the calendar dimension, if we have fact table, from we can get minimum and maximum date. Using these dates we can create calendar dimension which will include quater information , year, month, day, date and others.
 
ODBC CONNECT TO [oracle_scott;DBQ=ORCL ];

Base:
LOAD EMPNO,
    ENAME,
    JOB,
    MGR,
    date(HIREDATE,'DD/MM/YYYY') as HIREDATE,
    SAL,
    COMM,
    DEPTNO;
SQL SELECT *
FROM SCOTT.EMP;


minMaxdate:
Load min(HIREDATE,'DD/MM/YYYY') as minDate, max(HIREDATE,'DD/MM/YYYY') as maxDate Resident Base;

Let vminDate = num(peek('minDate',0,'minDate'));
Let vmaxDate = num(peek('maxDate',0,'maxDate'));

cal1:
load
    IterNo() as num1,
    $(vminDate) + IterNo() - 1 as Num,
    date($(vminDate) + IterNo()-1) as TempDate
AutoGenerate 1 While
$(vminDate)+IterNo()-1 <= $(vmaxDate);

cal2:
load
    Num as DateSeq,
    TempDate as TheDate,
    Month(TempDate) as month,
    num(Month(TempDate)) as MonthSeq,
    Year(TempDate) as yearSeq,
    day(TempDate) as DaySeq
Resident cal1
order by TempDate ASC;

//drop table cal1;

cal3:
LOAD
    DateSeq,
    TheDate as HIREDATE,
    yearSeq,
    month,
    MonthSeq,
    DaySeq,
    MonthSeq + (yearSeq - 1) *12 as MonthSeq1,
    Ceil(MonthSeq/3) as quarter,
    'Q'&     Ceil(MonthSeq/3) as quarter1,
    WeekDay(TheDate) as DayName
Resident cal2
order by TheDate ASC;



Thursday, August 28, 2014

QV15 Hierarchy In QLIKVIEW

QLIKVIEW wow, a great tool again. Solve the big problem of hanling the hierarchical data.
We have two function at all, which can be used at script level
 - hierarchy(upto 8 variables can pass)
 - hierarchybelongsto( 6 variables can pass.)


both function can use in front of LOAD statement or SELECT.

hierarchy:
it convert the node adjacent table to , in that way each level of child record will written in separate field.

Lets do some handsome practice on table - scott.emp !!!!!!!!

create connection
load the table
below the script you direct copy paste to your script editor after adding connection, i have three set of queries we will see the behaviour of each set of queries one by one:

//HIERARChy(EMPNO,MGR,ENAME)
//LOAD EMPNO,
// ENAME,
// JOB,
// MGR,
// SAL;
//SQL SELECT *
//FROM SCOTT.EMP;



 
:::
HIERARChy(EMPNO,MGR,ENAME)
it has three fields:
1. field1 i.e. empno - that has child records only
2. field2 i.e. mgr - reference to parent records
3. field3 i.e. ename - any column name can be used, depend on us what type of data we want to show in hierarchical manner.
 here i want to see the employee name in hierarchical order.


HIERARChy(EMPNO,MGR,ENAME,asdf,ENAME,[hierarchy_goeg], ';', 'HIERARCHY DEPTH')
LOAD EMPNO
,
ENAME
,
JOB
,
MGR
,
SAL
;
SQL
SELECT *
FROM SCOTT.EMP;





:::
HIERARChy(EMPNO,MGR,ENAME,asdf,ENAME,[hierarchy_goeg], ';', 'HIERARCHY DEPTH')it has three fields:
1. field1 i.e. empno - that has child records only
2. field2 i.e. mgr - reference to parent records
3. field3 i.e. ename - any column name can be used, depend on us what type of data we want to show in hierarchical manner.
 here i want to see the employee name in hierarchical order.
4. asdf - i use any dummy name .. either we can use the parent record description related field
5. ENAME - PathSource: The path in QlikView is a string containing one field per ancestor down to the node.
6. PathName: the name of the field that will contain the path.
7. Delimiter: the letter to separate the different fields
8. HIERARCHY DEPTH -the name of the field that will contain the depth of the node.





hierarchybelongsto:
The hierarchybelongsto prefix is used to transform a hierarchy table adjacent node table. Adjacent node table is the table where each record corresponds to a node and has a field that contains a reference to the parent node. (means table will store data in parent child relation help of two fields, parent record repeated over row untill all child has been written corespond to parent. see the below image first two field behaviour, it is a adjacent node table)
:::
HierarchyBelongsTo(EMPNO,MGR,ENAME, 'ANCESTORS_KEY','ANCESTORS_NAME', 'Depth')
it has three fields:
1. field1 i.e. empno - that has child records only
2. field2 i.e. mgr - reference to parent records
3. field3 i.e. ename - any column name can be used, depend on us what type of data we want to show in hierarchical manner.
 here i want to see the employee name in hierarchical order.
4. write parent record in field
5. write child record in field
6. Depth - depth number of record (0 for child node, summing up with 1 for roots)


geo2:
HierarchyBelongsTo(EMPNO,MGR,ENAME, 'ANCESTORS_KEY','ANCESTORS_NAME', 'Depth')
LOAD EMPNO
,
ENAME
,
JOB
,
MGR
,
SAL
;
SQL
SELECT *
FROM SCOTT.EMP;





 

Thursday, August 21, 2014

QV14 Peek() used in for loop

Peek() function can also most usable in for loop in qlikview.
Lets have a look on a little example, I have google-ed this example and perform on my local machine.

In the example, we have a table "FileListTable:" with two fields Date1 and FilNme. FilNme i.e. Filename all are exists on the loacal harddisk, we have to load each file and we can perform any type of string operation on loaded file.
In for loop:
1. NoOfRows return total number of rows in table
2. for loop work from bottom to up. As the logic says "vFileNo-1", Total no. of rows-1
 i.e.  11-1 = 10 return -> Airline Operations_ch8.qvw.2014_07_28_12_18_30.log
   10-1 = 9   Airline Operations_ch8.qvw.2014_07_28_11_34_41.log
   9-1 = 8    Airline Operations_ch8.qvw.2014_07_25_16_51_02.log
   ....
   2-1 = 1    Airline Operations_ch8.qvw.2014_07_25_15_38_06.log
   1-1 = 0    Airline Operations_ch8.qvw.2014_07_25_15_36_35.log

3. In loop we are creating New file name which will same the log file in the form of text file.
4. Store all log file in form of "*.txt"







FileListTable:
Load * inline
[
Date1, FilNme
18-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_36_35.log
25-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_38_06.log,
26-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_39_08.log,
27-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_50_00.log,
19-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_50_37.log,
20-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_53_15.log,
21-07-2014, Airline Operations_ch8.qvw.2014_07_25_15_57_28.log,
22-07-2014, Airline Operations_ch8.qvw.2014_07_25_16_48_30.log,
23-07-2014, Airline Operations_ch8.qvw.2014_07_25_16_51_02.log,
24-07-2014, Airline Operations_ch8.qvw.2014_07_28_11_34_41.log,
28-07-2014, Airline Operations_ch8.qvw.2014_07_28_12_18_30.log
]
; 


For vFileNo = 1 to NoOfRows('FileListTable')
      Let vFilNme = Peek('FilNme',vFileNo-1,'FileListTable');
       xyz: Load *,'$(vFilNme)' as FilNme
       From
[$(vFilNme)];      
       let vfilenme =replace(vFilNme,'.log','.txt') ;
       store * from xyz into $(vfilenme);
Next vFileNo

 

QV13 Peek() and previous()

the Peek() function allows the user to look into a field that was not previously loaded into the script
whereas the
Previous() function can only look into a previously loaded field.


Both are Inter Record Functions.These functions are used when a value from previously loaded records of data is needed for the evaluation of the current record.  IT loads the value from currently evaluating column. which is being in process and look into the previous value for that column.

peek(fieldname [ , row [ , tablename ] ] )
Returns the contents of the fieldname in the record specified by row in the internal table tablename. Data are fetched from the associative QlikView database.
Fieldname must be given as a string (single quote).

Row must be an integer.
  • 0 denotes the first record,
  • 1 the second and so on.
  • Negative numbers indicate order from the end of the table. -1 denotes the last record read.
  • If no row is stated, -1 is assumed.
     
If no tablename is stated, the current table is assumed.


previous(expression )
Returns the value of expression using data from the previous input record. In the first record of an internal table the function will return NULL because no previous record exists for first value.

The previous function may be nested.
Data are fetched directly from the input source, making it possible to refer also to fields which have not been loaded into QlikView, i.e. even if they have not been stored in its associative database.

Some similarities and differenceThe Similarities
 - Both allow you to look back at previously loaded rows in a table.
 - Both can be manipulated to look at not only the last row loaded but also previously loaded rows.
The Differences - Previous() operates on the Input to the Load statement, whereas Peek() operates on the Output of the Load statement. (Same as the difference between RecNo() and RowNo().) This means that the two functions will behave differently if you have a Where-clause.
 - The Peek() function can easily reference any previously loaded row in the table using the row number in the function  e.g. Peek(‘Employee Count’, 0)  loads the first row. Using the minus sign references from the last row up. e.g. Peek(‘Employee Count’, -1)  loads the last row. If no row is specified, the last row (-1) is assumed.  The Previous() function needs to be nested in order to reference any rows other than the previous row e.g. Previous(Previous(Hires))  looks at the second to last row loaded before the current row.

So, when is it best to use each function?    The previous() and peek() functions could be used when a user needs to show the current value versus the previous value of a field that was loaded from the original file. 
    The peek() function would be better suited when the user is targeting either a field that has not been previously loaded into the table or if the user needs to target a specific row.

source http://community.qlik.com/blogs/qlikviewdesignblog/2013/04/08/peek-vs-previous-when-to-use-each

//example1

DR:
LOAD F1, F2, Peek(F1) as PeekVal, Peek('F1',1,'DR') as PeekVal1, Previous(F2) as PrevVal ;
// Where F2 >= 200;
LOAD * INLINE
[
F1, F2
A, 100
B, 200
C, 150
D, 320
E, 222
F, 903
G, 666
]
;



//example2

data of file "9_Peek vs Previous.xlsx"
Date Hired Terminated
1/1/2011 6 0
2/1/2011 4 2
3/1/2011 6 1
4/1/2011 5 2
5/1/2011 3 2
6/1/2011 4 1
7/1/2011 6 2
8/1/2011 4 1
9/1/2011 4 0
10/1/2011 1 0
11/1/2011 1 0
12/1/2011 3 2
1/1/2012 1 1
2/1/2012 1 0
3/1/2012 3 1
4/1/2012 3 4
5/1/2012 2 1
6/1/2012 1 0
7/1/2012 1 0
8/1/2012 3 0
9/1/2012 4 3
10/1/2012 0 3
11/1/2012 2 1
12/1/2012 0 0
1/1/2013 4 2
2/1/2013 2 2
3/1/2013 3 0


[Employees Init]:


LOAD
rowno() as Row
,
Date(Date) as Date
,
Hired
,
Terminated
,
If(rowno()=1, Hired-Terminated, peek([Employee Count], -1)+(Hired-Terminated)) as [Employee Count]

From
[..\datafiles\9_Peek vs Previous.xlsx]
(ooxml, embedded labels, table is
Sheet2);

[Employee Count]:
LOAD

Row
,
Date
,
Hired
,
Terminated
,
[Employee Count]
,
If(rowno()=1,0,[Employee Count]-Previous([Employee Count])) as [Employee Var]

Resident [Employees Init] Order By Row asc;

Drop Table
[Employees Init];




image explanation
1. hierd - no of employee hiered
2. Terminated - no. of emp terminated
3. [Employee count] - accumalation(no of working employee - terminated employees)
we used peek function to get the desire result
4. [Employee Var] - employee variation from field [Employee count] using previou().

//now if you observe that we use previous() in different load query, because previous work on pre-loaded field.
//If we try to use previous() in load table "[Employees Init]" then it will not work, because "[Employee Count]" is being calculated in "[Employee Count]" load statement.

web stats