Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Exclude days in an expression using a field

Hi all,

Is there a way to exclude certain dates in an expression without having to type them out every time?

To calculate the amount of working days in a month, I use the following expression:

=NetWorkDays(MakeDate(only(Year),only(Month),1),MonthEnd(MakeDate(only(Year),only(Month),1)), '11/11/2015', '25/12/2015', '01/01/2016', '28/03/2016')

But I would like to use some kind of new field containing all of the dates I would like to exclude, so I could use something like:

=NetWorkDays(MakeDate(only(Year),only(Month),1),MonthEnd(MakeDate(only(Year),only(Month),1)), 'holidays')

With the new field being: holidays = '11/11/2015', '25/12/2015', '01/01/2016', '28/03/2016'

Is that possible?

Thanks in advance!

1 Solution

Accepted Solutions
swuehl
MVP
MVP

In this specific case, you can't use a fied for the holidays, it needs to be a comma separated list of arguments.

You can use a variable that dollar-sign expand to this argument list:

Open variable overview and create a new variable vHolidays with value (no leading equal sign in the value definition!):

'11/11/2015', '25/12/2015', '01/01/2016', '28/03/2016'

Then use it like

NetWorkDays(MakeDate(only(Year),only(Month),1),MonthEnd(MakeDate(only(Year),only(Month),1)),$(vHolidays))

View solution in original post

5 Replies
Gysbert_Wassenaar

You can create a variable that contains the list of holidays:

SET vHolidays = '11/11/2015', '25/12/2015', '01/01/2016', '28/03/2016';

You can then use that variable in the expression

=NetWorkDays(MakeDate(only(Year),only(Month),1),MonthEnd(MakeDate(only(Year),only(Month),1)),$(vHolidays))


If you have a table that contains the holiday dates you can collect them from there:


Temp:

LOAD concat(distinct chr(39 & MyHolidayDate & chr(30)) as HolidayList From MyHolidayTable;

LET vHolidays = peek('HolidayList');

Drop Table Temp;


talk is cheap, supply exceeds demand
swuehl
MVP
MVP

In this specific case, you can't use a fied for the holidays, it needs to be a comma separated list of arguments.

You can use a variable that dollar-sign expand to this argument list:

Open variable overview and create a new variable vHolidays with value (no leading equal sign in the value definition!):

'11/11/2015', '25/12/2015', '01/01/2016', '28/03/2016'

Then use it like

NetWorkDays(MakeDate(only(Year),only(Month),1),MonthEnd(MakeDate(only(Year),only(Month),1)),$(vHolidays))

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Hope below link will help.

Find Net Working Days

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Hello Swuehl,

Is this the way to add the variable, 'cus it gives me red lines already..

Edit: IT WORKS!! Thanks a bunch Swuehl, this is exactly what I needed!

Gysbert_Wassenaar

Yes, that's fine. The expression editor syntax checker tries to evaluate it as an expression. Well, it's not a valid expression. But it is simply a comma separated list of values which is what it should be.


talk is cheap, supply exceeds demand