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: 
aetingu12
Creator
Creator

Scripting Relative Dates Based on Latest Date

Dear all,

I have a date field SUMMARY_DATE (31/05/2018) and for simplicity in coding, I would like to create another field where I can mark the latest date as zero and the prior as:

SUMMARY_DATE          RELATIVE_MONTH

31/05/2018                                   0

30/04/2018                                  -1

31/03/2018                                  -2

28/02/2018                                  -3

31/01/2018                                  -4

Ideally within my Script.

Thanks for all the help,

Aksel

1 Solution

Accepted Solutions
sunny_talwar

This might be another way...

Table:

LOAD * INLINE [

    SUMMARY_DATE

    31/05/2018

    30/04/2018

    31/03/2018

    28/02/2018

    31/01/2018

];


FinalTable:

LOAD SUMMARY_DATE,

RangeSum(Peek('RELATIVE_MONTH'), (Year(SUMMARY_DATE)*12 + Month(SUMMARY_DATE))-(Year(Previous(SUMMARY_DATE))*12 + Month(Previous(SUMMARY_DATE)))) as RELATIVE_MONTH

Resident Table;


DROP Table Table;

View solution in original post

3 Replies
olivierrobin
Specialist III
Specialist III

hello

why not :

loading your date in a table

loading a 2nd table from the previous resident on order by date descending

computing a field with -1*rowno()+1

sunny_talwar

This might be another way...

Table:

LOAD * INLINE [

    SUMMARY_DATE

    31/05/2018

    30/04/2018

    31/03/2018

    28/02/2018

    31/01/2018

];


FinalTable:

LOAD SUMMARY_DATE,

RangeSum(Peek('RELATIVE_MONTH'), (Year(SUMMARY_DATE)*12 + Month(SUMMARY_DATE))-(Year(Previous(SUMMARY_DATE))*12 + Month(Previous(SUMMARY_DATE)))) as RELATIVE_MONTH

Resident Table;


DROP Table Table;

aetingu12
Creator
Creator
Author

Thank you very much.