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: 
Not applicable

How to sum based on dates

Hello,

I have the need to sum a value based on the closest matching date to another.  I have a score that is pulled at a date and tied to a customer but not directly tied to a transaction.  The date the score is pulled is stored and the date the transaction executed is stored.  Since the score is not tied to the transaction and to the customer my data is not showing properly.  So I would like to put some set analysis in so that I only grab the score from the closest date prior to the execution date.

From the dummy data below I would only want to see the first row, I have tried a few things but no luck.  Any help would be much appreciated.

Trans IDScore ScoreDateExecution DateAmount
12344503/31/20154/15/2015200
12345601/20/20154/15/2015200
16 Replies
sunny_talwar

May be this:

Table:

LOAD [Trans ID],

    Score,

    ScoreDate,

    [Execution Date],

    Amount,

    [Execution Date] - ScoreDate as Range

FROM

[https://community.qlik.com/thread/217587]

(html, codepage is 1252, embedded labels, table is @1);

Left Join (Table)

LOAD [Trans ID],

  Min(Range) as Range,

  If(Min(Range) > 0, 1) as Flag

Resident Table

Group by [Trans ID];

Not applicable
Author

That is close but if the value for the Transaction is less than 0 I would want to take the lowest positive value and this doesn't mark any flags for that transaction. 

sunny_talwar

When you say value, do you mean Score or Amount?

Not applicable
Author

I meant the Range.  I actually was able to complete it.

Left Join (Table)

LOAD [Trans ID],

  Min(Range) as Range,

  1 as Flag

Resident Table

Where Range >0

Group by [Trans ID];

sunny_talwar

Great

Not applicable
Author

Thank you very much for your help.

sunny_talwar

No problem at all. I am glad I was able to help