Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
ahmadov_10
Contributor
Contributor

Calculate sum amount based on Date conditions

Hi Experts,

i tried to work to calculate the sum(amount_pg) between the two dates in calendar choices (with Date range picker) . but when i modify the date filters , any modification for the the sum amount is maked to satisfy the conditions.

Any help please for a nice practice , method , extension to calculate sum based on dates condition ( i tried many but don't find the solution yet)

qq1.PNGqq2.PNG

7 Replies
Shubham_Deshmukh
Specialist
Specialist

Have you inserted if condition properly?

=Sum(if(date>=calendarObject1 and date <=calendarObject1,amount_pg))

ahmadov_10
Contributor
Contributor
Author

=Sum(if(date>=calendarObject1 and date <=calendarObject1,amount_pg))

date (is my date of course) but what do you mean by calendarObject1  : is undifined for Qlik sense and i should correct my syntax. So , the problem how to set the two dates in choice into 2 variables ? this is what we need : sur a simple configuration we must do it ? any help 

 

vitaliichupryna
Creator III
Creator III

Hi,
When you use Date range picker you use one Data field: for example Date.
In this case for correct calculation you should have min and max date from picker, in your example is:
min = 01/01/2018 and max 31/07/2018
For this you should create two variables MinDate: Min(Date) and MaxDate: Max(Date)
After this you can use variables in your set expressions:
sum({<Date = {">=$(MinDate)<=$(MaxDate)"}>}amount_pg)
Thanks,
Vitalii
Shubham_Deshmukh
Specialist
Specialist

I meant startDate and endDate which you used for calendar,
=Sum(if(date>=vStartDate and date <=vEndDate,amount_pg))
//date - your database date
//vStartDate and vEndDate are variables which you have used in calendars

As Vitalii suggested, you can also use set analysis for that,
=sum({<Date = {">=$(vStartDate )<=$(vEndDate)"}>}amount_pg)

ahmadov_10
Contributor
Contributor
Author

Thanks for your answer but  I still having problem : i make this configuration to the date range picker and my text with measure .  DATFCH : date orders / MNTFCH : amount orders

cc1.PNGcc2.PNGcc3.PNG

But i still having the same amount 😞   

ahmadov_10
Contributor
Contributor
Author

to understand me more : i need to calculate my sum(MNTFCH) dynamically , based on the dates in filter from the date range picker (or other extension object , the essential : finding solution)

vitaliichupryna
Creator III
Creator III

You can use my solution