Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to find the closest date?

I need a function where I can find the most approximate date in the past to one supplied as a parameter. To be more clear, based on an invoiced date, I need to look up the order date with a set analysis function. Since the order date can be anywhere from 1 to 7 days in the past, (and obviously no order number linking both tables) I need to, based on the client number and date of a certain invoice, find the corresponding shipping date. I thought something like firstsortedvalue or max(<{OrderDate={"<$(=InvoiceDate)"}}> OrderDate) would work, but it's not happening. Thanks!

4 Replies
johnw
Champion III
Champion III

Well, set analysis is in the context of the whole document, not just one row on the table, so that's probably why the expression isn't working. I'm guessing you could do the equivalent IF statement, and it might work since IF statements are in the context of the row:

max(if(OrderDate<InvoiceDate,OrderDate))

Not applicable
Author

yes, the shipped date and invoiced date are on separate tables, not on the same row. sorry if it wasn't clear.

johnw
Champion III
Champion III

I didn't think that mattered if the tables are connected, and they should be by the client number. Maybe I'm missing something.

Not applicable
Author

Nevermind, I solved it with the following expression:


Sum({1<OrderDate={"$(=max({1<OrderDate={"<$(=date(InvoiceDate))"}>} OrderDate))"}>} Amount)