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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
wunderch
Creator
Creator

Sort List by Date from and Date to

Hi guys,

I have a table like this:

productdate_fromdate_toprice
A18.02.202531.12.999989,99
A08.03.202431.12.999979,99
A29.01.202417.02.202469,99
A12.01.202431.12.999975,99
A21.11.202331.12.999984,99

 

and i want to sort the table like this:

productdate_fromdate_toprice
A18.02.202531.12.999989,99
A08.03.202417.02.202579,99
A18.02.202407.03.202475,99
A29.01.202417.02.202469,99
A12.01.202428.01.202475,99
A21.11.202311.01.202484,99

 

Can anybody help me?

Thanks 

Regards 

Chris

Labels (1)
9 Replies
PrashantSangle

what is the logic for 3rd line

A 18.02.2024 07.03.2024 75,99

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Vegar
MVP
MVP

Can you try to put words to the logic you want? That is often helpful when trying to find a solution.

My first impression of your query is that you will need to do some kind of comparison and select between the date_to value and the date_from value on the row above.

Helpful function to consider are peek(),  rangemin()/rangemax() and maybe coalesce()/alt().

wunderch
Creator
Creator
Author

Sorry for my quick question. Here is my logic:

Yes, I would like to put the sentences into a time series by comparing the date from and the date to.

To get the "date_to" from the next "date_from-1" is not the challenge. I get this with peek().

My problem is how can i get the additional row "18.02.2024" - "07.03.2024" because the row  from "29.01.2024" is only valid to 17.02.2024 and the next row is only valid from 08.03.2024.
So i have to create a row with the last row 12.01.2024.

I hope you unterstand my challenge?

 

wunderch
Creator
Creator
Author

Sorry for my quick question. Here is my logic:

Yes, I would like to put the sentences into a time series by comparing the date from and the date to.

To get the "date_to" from the next "date_from-1" is not the challenge. I get this with peek().

My problem is how can i get the additional row "18.02.2024" - "07.03.2024" because the row  from "29.01.2024" is only valid to 17.02.2024 and the next row is only valid from 08.03.2024.
So i have to create a row with the last row 12.01.2024.

I hope you unterstand my challenge?

PrashantSangle

& what is logic for price?

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
wunderch
Creator
Creator
Author

It's actually the same logic.

Take the last valid price.

In this case, it's the rate from January 12, 2024, because it's valid until infinity, and the next price is only valid from March 8, 2024.

marcus_sommer

You need to apply the interrecord-stuff with peek() and previous() twice. The first one checked if a real and valid to-date exists and if this fits to it's previous from-date - if not you set a flag-value of 2 and otherwise it's 1.

The next step is performing a while-loop, like:

load * resident while iterno() <= MyFlag;

which adds an extra record for those records which have a date-gap and then the final from-to data are evaluated per interrecord-functions.

wunderch
Creator
Creator
Author

Thank you for the answer.

I understand the logic, but unfortunately I can't convert it into the correct code.

Can you please give me an example of what the code should look like?

marcus_sommer

It may go in this direction whereby you may need some more if-loops especially for the extra records and/or further adjustments, for example the date-offset between the normal and extra records.

load *, if(product = previous(product), previous(from) - 1, ...) as to2;
load * while iterno() <= flag;
load *, if(product = previous(product) and to < '31.12.9999' and previous(from) - to > 1, 2, 1) as flag
resident X order by product, from desc;