Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Checco
Contributor
Contributor

How to calculate the difference in days between two dates in the same column

In input of the script I have a table like:

Checco_0-1662467458187.png

How can I calculate, for each row, the difference between the date and the date of the next row?
I would like to get a table like the one below

Checco_1-1662467562226.png

 

thank All

 

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

Just try it with the suggested approach. Further your peek() solution didn't fetch the data from the current load else it looped through the previous table - that's very seldom a sensible method.

To see what really happens you may add a recno() and a rowno() to comprehend which origin records where now loaded in which order - that's the essential part to fetch the right data from the wanted rows.

- Marcus

View solution in original post

6 Replies
SchalkF
Contributor III
Contributor III

Hi Checco,

Do you want to achieve this in the load editor or in a table visualization?

In your load editor you would use  the following statement to get the value in the next row:

Day#(DATA - Peek(DATA, RowNo()+1), 'dd')

Kind regards

Checco
Contributor
Contributor
Author

Thanks Schalkf

Excuse me but if I submit the script

Tab1:
LOAD ID,
DATA
FROM [File1.xlsx] (ooxml, embedded labels, table is Foglio1);

RESULT:
LOAD ID, DATA,
(DATA - Peek(DATA, RowNo() +1 ), 'dd') as day
RESIDENT Tab1
ORDER BY ID;

I get the error:

Checco_0-1662470562475.png

 

marcus_sommer

Try it with:

Tab1:
LOAD ID,
DATA
FROM [File1.xlsx] (ooxml, embedded labels, table is Foglio1);

RESULT:
LOAD ID, DATA,
DATA - previous(DATA) as DataDiff
RESIDENT Tab1
ORDER BY ID, DATA desc;

- Marcus

Checco
Contributor
Contributor
Author

Hello everybody.
I tried to modify my load script (see attached file).
Can anyone tell me why the "Final Table" gives me the error in the last row: the date after 13/07/2022 is 12/07/2022 and not 18/07/2022 !!!!

Thank you all

marcus_sommer

Just try it with the suggested approach. Further your peek() solution didn't fetch the data from the current load else it looped through the previous table - that's very seldom a sensible method.

To see what really happens you may add a recno() and a rowno() to comprehend which origin records where now loaded in which order - that's the essential part to fetch the right data from the wanted rows.

- Marcus

Checco
Contributor
Contributor
Author

thank 1000 Marcus