Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
ronaldwang
Creator III
Creator III

Sum only if the difference between two fields are greater than a certain amount (30 days).

how to use expression to Sum only if the difference between two fields are greater than a certain amount (30 days). Say if the two fields are paymentdate and invoice date

I have tried

 

sum({$<[Payment Date]={">=[Invoice Date]+30"}>}Amount)

 

1 Solution

Accepted Solutions
Anil_Babu_Samineni

I assume, First one also should work. Might this problem with Date.

Again,

If(Interval(Date(Date#([invoice date],'Having Format'),'Required Format') - Date(Date#([Payment date],'Having Format'),'Required Format'), 'DD') < 30, 1, 0)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful

View solution in original post

7 Replies
shraddha_g
Partner - Master III
Partner - Master III

try,

sum({$<[Payment Date]={">=$(=date(max([Invoice Date])+30))"}>}Amount)

Anil_Babu_Samineni

There is no aggregation calculation in your sub set analysis which is Max, Min, Sum, Count. can you explain the requirement?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
ronaldwang
Creator III
Creator III
Author

 

The requirement is that for a number of transactions (where  [invoice date] and [Payment date] is 2 of the fields. And I want to add up the amount where the difference between the [invoice date] and [Payment date] is less than 30 days. (based on the assumption that I am not to load the [Payment date]-[invoice date] into my data model. thanks

 

Anil_Babu_Samineni

May be this?

Sum({<[invoice date] = {"=([invoice date] - [Payment date]) < 30"}>} Amount)


OR

In script, create one flag

If([invoice date] - [Payment date] < 30, 1, 0) as Flag

OR

If(NetWorkDays([invoice date] - [Payment date]) < 30, 1, 0) as Flag

And set analysis should be

Sum({<Flag = {1}>} Amount)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
ronaldwang
Creator III
Creator III
Author

the first option is not working and probably I have to go to change the datamart to flag it. thanks Anil

Anil_Babu_Samineni

I assume, First one also should work. Might this problem with Date.

Again,

If(Interval(Date(Date#([invoice date],'Having Format'),'Required Format') - Date(Date#([Payment date],'Having Format'),'Required Format'), 'DD') < 30, 1, 0)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
ronaldwang
Creator III
Creator III
Author

Thanks Anil, it is working