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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Samanehsorournejad

Calculating the number of Days between two dates extract holidays

Hi everyone,

I want to calculate the different between 2 column's date but it should not calculate the holidays or weekend.

for different between 2 days I had used

floor([Resolution Date]​) - Floor([Date Created])

 but  I don't know how to extract holidays.

 

I would be so thankful if anyone help me 🙂

Labels (2)
2 Solutions

Accepted Solutions
cristianj23a
Partner - Creator III
Partner - Creator III

Hello, what you should do is create a table with your holidays and holidays, then create a flag so you can filter in the expressions, something like that.

//Create inline table of examples with holidays

HolidayDates:
Mapping
LOAD * inline [
HolidayDate,Flag
2023-01-01,1
2023-04-14,1
2023-07-04,1
2023-03-25,1
];

//Create master calendar table

LET vDateMin = Num(MakeDate(2023, 1, 1));
LET vDateMax = Num(Today());

[Temporary Calendar]:
LOAD $(vDateMin) + RowNo() - 1 as [Num Date],
Date($(vDateMin) + RowNo() - 1) as Date
AUTOGENERATE 1
WHILE $(vDateMin) + IterNo() - 1 <= $(vDateMax);

[Master Calendar]:
LOAD Date,
Year(Date) AS Year,
'S' & Ceil(Month(Date)/6) as Semester,
'Q' & Ceil(Month(Date)/3) as Trimester,
Month(Date) AS Month,
WeekDay(Date) AS Week,
Day(Date) AS Day,
WeekDay(Date) & '-' & Day(Date) AS PerWeek,
Num(Month(Date), '00') AS [Num Month],
Month(Date) & '-' & Right(Year(Date), 2) AS [Year Month],
Year(Date) & Num(Month(Date), '00') AS [NumYearMonth],
ApplyMap('HolidayDates',Date,0) AS Flag
RESIDENT [Temporary Calendar]
Order By Date Asc;

DROP TABLE [Temporary Calendar];

 

As you will see, a flag was created that has value 1 and 0, you use that in the expressions.
Example:

Sum({<Flag={'0'}>} Sales)

 

You can also review this code where the business days are obtained but the holidays are not considered since it is independent by country.

https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeFunc...

 

Greetings.

 
https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.

View solution in original post

vinieme12
Champion III
Champion III

Use the NetWorkDays() functions

 

https://help.qlik.com/en-US/qlikview/May2023/Subsystems/Client/Content/QV_QlikView/Scripting/DateAnd...

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

2 Replies
cristianj23a
Partner - Creator III
Partner - Creator III

Hello, what you should do is create a table with your holidays and holidays, then create a flag so you can filter in the expressions, something like that.

//Create inline table of examples with holidays

HolidayDates:
Mapping
LOAD * inline [
HolidayDate,Flag
2023-01-01,1
2023-04-14,1
2023-07-04,1
2023-03-25,1
];

//Create master calendar table

LET vDateMin = Num(MakeDate(2023, 1, 1));
LET vDateMax = Num(Today());

[Temporary Calendar]:
LOAD $(vDateMin) + RowNo() - 1 as [Num Date],
Date($(vDateMin) + RowNo() - 1) as Date
AUTOGENERATE 1
WHILE $(vDateMin) + IterNo() - 1 <= $(vDateMax);

[Master Calendar]:
LOAD Date,
Year(Date) AS Year,
'S' & Ceil(Month(Date)/6) as Semester,
'Q' & Ceil(Month(Date)/3) as Trimester,
Month(Date) AS Month,
WeekDay(Date) AS Week,
Day(Date) AS Day,
WeekDay(Date) & '-' & Day(Date) AS PerWeek,
Num(Month(Date), '00') AS [Num Month],
Month(Date) & '-' & Right(Year(Date), 2) AS [Year Month],
Year(Date) & Num(Month(Date), '00') AS [NumYearMonth],
ApplyMap('HolidayDates',Date,0) AS Flag
RESIDENT [Temporary Calendar]
Order By Date Asc;

DROP TABLE [Temporary Calendar];

 

As you will see, a flag was created that has value 1 and 0, you use that in the expressions.
Example:

Sum({<Flag={'0'}>} Sales)

 

You can also review this code where the business days are obtained but the holidays are not considered since it is independent by country.

https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeFunc...

 

Greetings.

 
https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.
vinieme12
Champion III
Champion III

Use the NetWorkDays() functions

 

https://help.qlik.com/en-US/qlikview/May2023/Subsystems/Client/Content/QV_QlikView/Scripting/DateAnd...

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.