Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
BernardBernoulli
Contributor III
Contributor III

Compare selected date range in date picker with previous dates

Hello,

we'd like to compare dates we select in a date picker with the previous dates of this exact selected amount of days.

So if we select an interval of 3 days to compare, we would like to compare these to the 3 days prior to these.

e.g.

We select the following dates:

12/02/2024
13/02/2024
14/02/2024

and want to compare these data to:

11/02/2024
10/02/2024
09/02/2024

Another example:

20/03/2024
21/03/2024
22/03/2024
23/03/2024

compare to:

19/02/2024
18/02/2024
17/02/2024
16/02/2024

Is this possible?

Labels (3)
1 Solution

Accepted Solutions
TauseefKhan
Creator III
Creator III

Hi @BernardBernoulli,

You will need variables to capture the selected date range and compute the previous date range.

// Assuming you are working with a field called 'Date'
SET vMaxSelectedDate = Max(Date);
SET vMinSelectedDate = Min(Date);
SET vDaysSelected = $(vMaxSelectedDate) - $(vMinSelectedDate) + 1; // Calculate the number of selected days

// Compute the previous date range
SET vPrevMaxDate = Date(AddMonths($(vMaxSelectedDate), -1)); // Last day of the previous period
SET vPrevMinDate = Date(AddMonths($(vMinSelectedDate), -1)); // First day of the previous period
SET vPrevDates = $(vMaxSelectedDate) - $(vPrevMaxDate); // The length of the previous period
Set Up Visualizations to Compare Date Ranges:



To compare the selected date range with the previous date range:

// Sales in the selected date range
Sum({<Date={">=$(vMinSelectedDate)<=$(vMaxSelectedDate)"}>} Sales)

// Sales in the previous date range
Sum({<Date={">=$(vPrevMinDate)<=$(vPrevMaxDate)"}>} Sales)


****Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.****

View solution in original post

2 Replies
Gabbar
Specialist
Specialist

Try These Expression to compare :-  
Base Data for selected Data :-  Sum(Data)
Selection Condition Filtering For Selection of other Dates:- 
Sum({<Date={">=$(=Min(Date)-Count(Date))<$(=Min(Date))"}>}Data)
and if date is in particular format then :-
Sum({<Date={">=$(=Date(Min(Date)-Count(Date),'DD/MM/YYYY'))<$(=Date(Min(Date),'DD/MM/YYYY'))"}>}Data)


If this Doesnt Work Try Changing The Dates in Numerical Figure in Script. 

TauseefKhan
Creator III
Creator III

Hi @BernardBernoulli,

You will need variables to capture the selected date range and compute the previous date range.

// Assuming you are working with a field called 'Date'
SET vMaxSelectedDate = Max(Date);
SET vMinSelectedDate = Min(Date);
SET vDaysSelected = $(vMaxSelectedDate) - $(vMinSelectedDate) + 1; // Calculate the number of selected days

// Compute the previous date range
SET vPrevMaxDate = Date(AddMonths($(vMaxSelectedDate), -1)); // Last day of the previous period
SET vPrevMinDate = Date(AddMonths($(vMinSelectedDate), -1)); // First day of the previous period
SET vPrevDates = $(vMaxSelectedDate) - $(vPrevMaxDate); // The length of the previous period
Set Up Visualizations to Compare Date Ranges:



To compare the selected date range with the previous date range:

// Sales in the selected date range
Sum({<Date={">=$(vMinSelectedDate)<=$(vMaxSelectedDate)"}>} Sales)

// Sales in the previous date range
Sum({<Date={">=$(vPrevMinDate)<=$(vPrevMaxDate)"}>} Sales)


****Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.****