Qlikview Tips

January 3, 2017 | Author: anbucheliyan | Category: N/A
Share Embed Donate


Short Description

Download Qlikview Tips...

Description

Qlikview Tips

Contributed By Anbu Cheliyan Version Number 1 Creation Date

06/05/2014

Page 1 of 7

Table of Contents

1 2 3 4 5

Sorting weekdays in different order..................................................................................2 Find bank having highest rate...........................................................................................2 Sequence number generation similar to row_number() over() in sql.........................4 Top 5 Salesman.................................................................................................................... 5 Cumulative sum in script..........................................................................................................5

Page 2 of 7

1

Sorting weekdays in different order If you want to order data from Wednesday through Tuesday, then add the below function in Sort  Expression Match(WeekField, 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday') Match function performs case sensitive comparison and returns integer value based on position of expression If WeekField='Wednesday', Match returns 1 If WeekField='Thursday', Match returns 2 …. If WeekField='Tuesday', Match returns 7

2

Find bank having highest rate Initial: LOAD * INLINE [ Bank, Rate A, 0.7 B, 0.8 C, 0.5 D, 1.2 E, 1.1 ]; Final: Load FirstSortedValue(Bank,-Rate), FieldValue('Bank',Fieldindex( 'Rate', max(Rate) )) Resident Initial; firstsortedvalue ([ distinct ] expression [, sort-weight [, n ]])

Returns the first value of expression sorted by corresponding sortweight when expression is iterated over a number of records as defined by a group by clause. Sort-weight should return a numeric value where the lowest value will render the corresponding value of expression to be sorted first. By preceding the sort-value expression with a minus sign, the function will return the last value instead.

Page 3 of 7

FirstSortedValue(Bank,-Rate) Returns Bank having highest Rate. Negative sign denotes order by Rate in descending Equivalent sql Select Bank From (Select Bank from Table Order by Rate Desc) Where rownum < 2

FieldIndex(fieldname , value ) Returns the position of the field value value found in the field fieldname (by load order). If value cannot be found among the field values, 0 is returned. fieldname must be given as a string value, e.g. the field name must be enclosed by single quotes. FieldValue(fieldname , n ) Returns the field value found in position n of the field fieldname (by load order). fieldname must be given as a string value, e.g. the field name must be enclosed by single quotes. The first field value is returned for n=1. If n is larger than the number of field values, NULL is returned. First I determine the row containing the highest rate: Fieldindex( 'Rate', max(Rate) ))--> row number 4 To retrieve the value of Bank in the 4th row: Fieldvalue('Bank',fieldindex( 'Rate', max(Rate) )) 3

Sequence number generation similar to row_number() over() in sql Input ID,LegID,Anode,Znode S1,MSB2,N2,N3 S1,MSB1,N1,N2 S1,MSB4,N4,N5 S1,MSB3,N3,N4 S2,MSB2,N2,N3 S2,MSB5,N3,N6 Page 4 of 7

Output: select ID,LegID, row_number() over(partition by ID order by LegID) from Table ID,Cktid, SequenceID S1,MSB1,1 S1,MSB2,2 S1,MSB3,3 S1,MSB4,4 S2,MSB2,1 S2,MSB5,2 Source: load * inline [ ID,LegID,Anode,Znode S1,MSB2,N2,N3 S1,MSB1,N1,N2 S1,MSB4,N4,N5 S1,MSB3,N3,N4 S2,MSB2,N2,N3 S2,MSB5,N3,N6 ]; table: load AutoNumber(LegID, ID) as Sequence, * Resident source order by ID, LegID; DROP Table source; autonumber(expression[ , AutoID]) Returns a unique integer value for each distinct evaluated value of expression encountered during the script execution. This function can be used e.g. for creating a compact memory representation of a complex key. In order to create multiple counter instances if the autonumber function is used on different keys within the script, an optional parameter AutoID can be used for naming each counter. Page 5 of 7

4

Top 5 Salesman 1. Using calculated dimension =IF(aggr(rank(sum(Sales)),Salesman) Max Number Set Max Number to 5 in Presentation tab and sort Sales on descending 3. Dimension limits Set Show only First 5 in Dimension limits tab and sort Sales on descending in Sort tab 4. Set analysis =sum({} Sales)

5 Cumulative sum in script Cumulative_sum: Load * Inline [ ID,a 1, 1 2, 3, 1 4, 1 5, ]; NoConcatenate table: load ID, RangeSum(a, Peek('CumSum')) AS CumSum Resident Cumulative_sum order by ID, a; Drop table Cumulative_sum; RangeSum(expr1 [ , expr2, ... exprN ]) Returns the sum of a range of 1 to N arguments. Rangesum will treat all non-numeric values and nulls as 0.

Page 6 of 7

Peek('CumSum') returns the value of cumulative sum in the previous record read ( equivalent to previous(CumSum) ).

6 Qlikview functions - Prefix zeros to a number and make four digit number Right(Repeat('0',4) & '12',4) - Case statement equivalent in Qlikview CASE WHEN PSWHSE = 001 THEN TRIM(PSAREA) || TRIM(PSZONE) || LEFT(TRIM(PSAISL,1)) || TRIM(PSBAY) WHEN PSWHSE = 003 THEN TRIM(PSAISL) || TRIM(PSLEVL) || TRIM(PSPOSN) WHEN PSWHSE = 031 THEN TRIM(PSAISL) || TRIM(PSLEVL) || TRIM(PSPOSN) END Pick(Match(PSWHSE,001,003,031) , TRIM(PSAREA) & TRIM(PSZONE) & LEFT(TRIM(PSAISL,1)) & TRIM(PSBAY) , TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN) , TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN) ) With else expression Pick(Match(PSWHSE,001,003,031)+1 , else_expression , TRIM(PSAREA) & TRIM(PSZONE) & LEFT(TRIM(PSAISL,1)) & TRIM(PSBAY) , TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN) , TRIM(PSAISL) & TRIM(PSLEVL) & TRIM(PSPOSN) )

Page 7 of 7

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF