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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
ellys
Contributor II
Contributor II

Using IF Statement to select a date

I am trying to create a measure counting the number of working days between a hire date and termination date using the formula below

NetWorkDays([hireDate],[terminationDate1])

This works for employees with a term date but returns blank when the term date is empty. How can I fix this such that if term date is blank, it uses Today as the end date in this formula?

Labels (1)
2 Solutions

Accepted Solutions
marcus_sommer

You may try: NetWorkDays([hireDate],alt([terminationDate1], today()))

View solution in original post

marcus_sommer

In general you could use alt() also for such tasks because it returns always the first numeric value which means it's just a matter to apply the n date-values in the wanted order.

A slightly other approach might be to replace alt() with a range-function, maybe like this one:

NetWorkDays(rangemin([hireDate], yearstart(today())),alt([terminationDate1], today()))

to define a certain min/max value. Such logic might also use combined and/or nested alt()/range-function approaches and/or including/wrapped by any if-loop-conditions.

Beside the above you may also consider to transfer the essential parts of the logic into the data-model, for example by defining the workingdays within the calendar - as flag-field with just 0/1 values and then a simple:

sum(FlagField)

would in regard to selection state also return the wanted results. 

View solution in original post

5 Replies
Bhushan_Mahajan
Creator II
Creator II

@ellys You can transform term date like if it is null consider today or today -1 as term date.

marcus_sommer

You may try: NetWorkDays([hireDate],alt([terminationDate1], today()))

ellys
Contributor II
Contributor II
Author

Marcus 

Thank you - that worked great - can I use similar logic with the start date - i.e. either hire date or a fixed point in time - for example first day of current month? In that situation the hire date would not be null or blank.

If I can then I could set up the formula to calculate between the later of start of period and hire date and the earlier of term date and today

Ellys

marcus_sommer

In general you could use alt() also for such tasks because it returns always the first numeric value which means it's just a matter to apply the n date-values in the wanted order.

A slightly other approach might be to replace alt() with a range-function, maybe like this one:

NetWorkDays(rangemin([hireDate], yearstart(today())),alt([terminationDate1], today()))

to define a certain min/max value. Such logic might also use combined and/or nested alt()/range-function approaches and/or including/wrapped by any if-loop-conditions.

Beside the above you may also consider to transfer the essential parts of the logic into the data-model, for example by defining the workingdays within the calendar - as flag-field with just 0/1 values and then a simple:

sum(FlagField)

would in regard to selection state also return the wanted results. 

ellys
Contributor II
Contributor II
Author

Marcus

I had to tweak your range suggestion slightly - using rangemax instead but it works. I am going to revisit the data model suggestion later but for now I have what I need.

Thank you for the help