Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Vegar
MVP
MVP

Preceding load on peek() tables

I  notice strange behaviour when performing a preceding load on a table generated using the peek function? Can anyone explain what's happening and why? @hic do you have an explanation?  

Example 1. Not using preceding load, the peek works at intended. On the Version 3 ValidTo I get the version 4 ValidFrom figures.  

image.png


Data: LOAD
rowno() as Id,
* inline [ Version, Location, ValidFrom 3, Uppsala, 2019-04-18 3, Storvreta, 2019-04-18 3, Tierp, 2019-04-18 4, Uppsala, 2019-04-19 4, Storvreta, 2019-04-19 4, Tierp, 2019-04-19 ]; PeekTable: LOAD Id, Version, Location, ValidFrom, If(peek('Location')=Location, peek('ValidFrom'), '9999-12-31') as ValidTo Resident Data ORDER BY Location, Version desc; DROP TABLE Data;

 

 

Example 2. Adding preceding load 

But if I add a preceeding load to my my peek table something strange happens.... all ValidTo ends up as 9999-12-31.Output using preceding load on peekOutput using preceding load on peek

Data:
LOAD 
rowno() as Id,
* inline [ Version, Location, ValidFrom 3, Uppsala, 2019-04-18 3, Storvreta, 2019-04-18 3, Tierp, 2019-04-18 4, Uppsala, 2019-04-19 4, Storvreta, 2019-04-19 4, Tierp, 2019-04-19 ]; Peek: LOAD Id, ValidTo ; PeekTable: LOAD Id, Version, Location, ValidFrom, If(peek('Location')=Location, peek('ValidFrom'), '9999-12-31') as ValidTo Resident
Data ORDER BY Location, Version desc; //DROP TABLE Data;

 

 

My workaround

Data:
LOAD rowno() as Id, * inline [
Version, Location,	ValidFrom
3,	Uppsala,	2019-04-18
3,	Storvreta,	2019-04-18
3,	Tierp,		2019-04-18
4,	Uppsala,	2019-04-19
4,	Storvreta,	2019-04-19
4,	Tierp,		2019-04-19
];

PeekTable:
LOAD
  Id, 
  Version,	
  Location,	
  ValidFrom,
  If(peek('Location')=Location, peek('ValidFrom'), '9999-12-31') as ValidTo
Resident Data
ORDER BY Location, Version desc;

Final:
LOAD 
  Id, 
  ValidTo
Resident PeekTable
;
DROP Table PeekTable;
Labels (5)
19 Replies
sunny_talwar

May be try this

Operations:
LOAD Customer_Slab,
	 Customer_Name,
	 Customer_Account_no,
	 Customer_Sales,
	 Total_Purchase,
	 If(Customer_Name = Previous(Customer_Name), RangeMax(RangeSum(Peek('result'), -Customer_Sales), 0), Total_Purchase - Customer_Sales) as result;
LOAD * INLINE [
    Customer_Slab, Customer_Name, Customer_Account_no, Customer_Sales, Total_Purchase, ZERO_COLUM
    7, Eric, Boston, 450, 5000, 0
    6, Eric, Boston, 500, 0, 0
    5, Eric, Boston, 320, 0, 0
    4, Eric, Boston, 250, 0, 0
    3, Eric, Boston, 140, 0, 0
    2, Eric, Boston, 659, 0, 0
    1, Eric, Boston, 370, 0, 0
    7, Monti, Kreta, 220, 2500, 0
    6, Monti, Kreta, 220, 0, 0
    5, Monti, Kreta, 180, 0, 0
    4, Monti, Kreta, 840, 0, 0
    3, Monti, Kreta, 1, 0, 0
    2, Monti, Kreta, 456, 0, 0
    1, Monti, Kreta, 6986, 0, 0
];

Capture.PNG

somacdc
Contributor III
Contributor III

But Sir, I'm using qvd except for an inline table because I have many data of the same. When Put the following into it. its descending order will be disturbed.

If(Customer_Name = Previous(Customer_Name), RangeMax(RangeSum(Peek('result'), -Customer_Sales), 0), Total_Purchase - Customer_Sales) as result;

this is my code.

CASH_ADJUSTED_TOTAL:
NoConcatenate
LOAD SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
TARIFF_DEDUCTED,
CASH_BALANCE,
// RangeMax(RangeSum(Alt(Peek('result'), CASH_BALANCE), -Rangesum(TARIFF_DEDUCTED)), 0) as result;
If(ELEMENT_ID = Previous(ELEMENT_ID) and Previous(ACCOUNT_NUMBER) = ACCOUNT_NUMBER, RangeMax(RangeSum(Peek('result'), -TARIFF_DEDUCTED), 0), CASH_BALANCE - TARIFF_DEDUCTED) as result;

LOAD SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
(SLAB & ELEMENT_ID & ACCOUNT_NUMBER) AS ORDER,
TARIFF_DEDUCTED,
SUM_TOTAL_AMOUNT,
MAX_SLAB,
If(STATUS = 'N' AND SLAB = MAX_SLAB, SUM_TOTAL_AMOUNT, 0) AS CASH_BALANCE,
If(STATUS = 'N', 'Y', 'N') AS STATUS

Resident CASH_DEPOSIT_TOTAL
ORDER BY ORDER DESC;

sunny_talwar

Not sure I understand your concern?

somacdc
Contributor III
Contributor III

I'm using qvd except for an inline table because I have many data of the same. its descending order and result  are disturbed.

Whenever I used particular Element id and Account number, its provide correct result and perfect descending order.

CASH_ADJUSTED_TOTAL:
NoConcatenate
LOAD SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
TARIFF_DEDUCTED,
CASH_BALANCE,
// RangeMax(RangeSum(Alt(Peek('result'), CASH_BALANCE), -Rangesum(TARIFF_DEDUCTED)), 0) as result;
If(ELEMENT_ID = Previous(ELEMENT_ID) and Previous(ACCOUNT_NUMBER) = ACCOUNT_NUMBER, RangeMax(RangeSum(Peek('result'), -TARIFF_DEDUCTED), 0), CASH_BALANCE - TARIFF_DEDUCTED) as result;

LOAD SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
(SLAB & ELEMENT_ID & ACCOUNT_NUMBER) AS ORDER,
TARIFF_DEDUCTED,
SUM_TOTAL_AMOUNT,
MAX_SLAB,
If(STATUS = 'N' AND SLAB = MAX_SLAB, SUM_TOTAL_AMOUNT, 0) AS CASH_BALANCE,
If(STATUS = 'N', 'Y', 'N') AS STATUS

Resident CASH_DEPOSIT_TOTAL
ORDER BY ORDER DESC;

sunny_talwar

result are disturbed? Can you show an image or a sample? I won't really know what disturbed means unless you provide more details

somacdc
Contributor III
Contributor III

Desire result:

ELEMENT_IDACCOUNT_NUMBERSLABTARIFF_DEDUCTEDCASH_BALANCEresult
0327773Slab 754558.86567000000566945441.14
0327773Slab 6180729830.33950386215610.8005
0327773Slab 5180729830.33950205485780.461
0327773Slab 4180729830.3395024755950.1215
0327773Slab 3180729830.339500
0327773Slab 2180729830.339500
0327773Slab 1180729830.339500

 

Please check the following which produced disturbing result and find the attache qvd.

DATA:
LOAD ELEMENT_ID,
ACCOUNT_NUMBER,
SUM(TOTAL_AMOUNT) AS SUM_TOTAL_AMOUNT,
MAX(SLAB) AS MAX_SLAB
FROM [QVDS\OUTPUT_1.qvd] (qvd)
WHERE REC_STATUS = 'N'
GROUP BY ELEMENT_ID,
ACCOUNT_NUMBER;

INNER JOIN
LOAD TARIFF_DEDUCTED,
SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
(ELEMENT_ID & ACCOUNT_NUMBER & SLAB) AS ORDER
FROM [QVDS\OUTPUT_1.qvd] (qvd);

CASH_ADJUSTED_TOTAL:
NoConcatenate
LOAD DISTINCT
ELEMENT_ID,
ACCOUNT_NUMBER,
'Slab ' & SLAB AS SLAB,
TARIFF_DEDUCTED,
CASH_BALANCE,
If(ELEMENT_ID = Previous(ELEMENT_ID) and ACCOUNT_NUMBER = Previous(ACCOUNT_NUMBER), RangeMax(RangeSum(Peek('result'), -TARIFF_DEDUCTED), 0), RangeMax((CASH_BALANCE - TARIFF_DEDUCTED), 0)) as result,
;
LOAD SLAB,
ELEMENT_ID,
ACCOUNT_NUMBER,
TARIFF_DEDUCTED,
MAX_SLAB,
If(SLAB = MAX_SLAB, SUM_TOTAL_AMOUNT, 0) AS CASH_BALANCE
Resident DATA
ORDER BY ORDER DESC;

DROP Table DATA;

ELEMENT_IDACCOUNT_NUMBERSLABTARIFF_DEDUCTEDCASH_BALANCEresult
0327773Slab 754558.86567000000566618088
0327773Slab 754558.86567000000566672646.8
0327773Slab 754558.86567000000566727205.7
0327773Slab 754558.86567000000566781764.6
0327773Slab 754558.86567000000566836323.4
0327773Slab 754558.86567000000566890882.3
0327773Slab 754558.86567000000566945441.1
0327773Slab 6180729830.300
0327773Slab 6180729830.3024428596.96
0327773Slab 6180729830.30205158427.3
0327773Slab 6180729830.30385888257.6
0327773Slab 5180729830.300
0327773Slab 4180729830.300
0327773Slab 3180729830.300
0327773Slab 2180729830.300
0327773Slab 1180729830.300

 

sunny_talwar

Where is the qvd?

somacdc
Contributor III
Contributor III

QVDS_DATA:
LOAD * FROM [QVDS\OUTPUT_1.qvd] (qvd);

ELEMENT_IDACCOUNT_NUMBERSLABTARIFF_DEDUCTEDREC_STATUSTOTAL_AMOUNT
03277731180729830.3N0
03277732180729830.3N0
03277733180729830.3N0
03277734180729830.3N0
03277735180729830.3N0
03277736180729830.3N0
0327773754558.86N81000000
somacdc
Contributor III
Contributor III

When open the qvd data, it has multiple record. I'm shocked that how to do it correct

clipboard_image_2.png

somacdc
Contributor III
Contributor III

I resolved by myself 🙂

Thanks for your support earlier.