Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
v_n
Contributor II
Contributor II

Calculation sum depending on the date difference

Hello everybody,

 

I am currently working on an application that will show me the total open items of our customers.

For this purpose, there are various time intervals of overdue, e.g. less than 0 days, 1 to 30 days, etc. I calculate this with the due date and a reference date:

= if(
Interval([reference_date]-[due_date],'d') <= 0, Sum([Amount])
)
= if(
Interval([reference_date]-[due_date],'d') <= 0 and Interval([reference_date]-[due_date],'d') <= 30, Sum([Amount])
)

 

This works as long as I have the due date as a dimension in my table.

As soon as I remove the due date from the table, nothing is calculated anymore.

 

How do I make the calculation work in aggregated form?

1 Solution

Accepted Solutions
sunny_talwar

Try this may be

=Sum(If(Interval([reference_date]-[due_date], 'd') <= 0, [Amount]))
= Sum(If(Interval([reference_date]-[due_date], 'd') > 0 and Interval([reference_date]-[due_date], 'd') <= 30, [Amount]))

But a more efficient way to do this would be to create a new field in the script

Interval([reference_date]-[due_date], 'd') as duration

and then use that in your set analysis

=Sum({<duration = {"<=0"}>}[Amount])
=Sum({<duration = {">0<=30"}>}[Amount])

View solution in original post

2 Replies
sunny_talwar

Try this may be

=Sum(If(Interval([reference_date]-[due_date], 'd') <= 0, [Amount]))
= Sum(If(Interval([reference_date]-[due_date], 'd') > 0 and Interval([reference_date]-[due_date], 'd') <= 30, [Amount]))

But a more efficient way to do this would be to create a new field in the script

Interval([reference_date]-[due_date], 'd') as duration

and then use that in your set analysis

=Sum({<duration = {"<=0"}>}[Amount])
=Sum({<duration = {">0<=30"}>}[Amount])
v_n
Contributor II
Contributor II
Author

Thank you! It works. 

The more efficient way does not work for me because I want to select the reference date in a filter within my app.

But the other solution is fine.