Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
TobiasTebben
Contributor III
Contributor III

Summing up values that change over time

Dear community,

I am trying really hard, but I keep failing with the following problem:

I have a table with the work hours of employees per day of week. Normally, for each employee there is one set of seven entries from Monday to Sunday. But some employees change their hours during the year, so there are multiple sets of entries for those people. My table looks something like this (in this examply, Paul changes from 40 to 32 hours per week beginning Feb 1):

EmployeeNoNameValidFromValidUntilWeekdayHours
1Paul2021/01/012021/01/31Mon8
1Paul2021/01/012021/01/31Tue8
1Paul2021/01/012021/01/31Wed8
1Paul2021/01/012021/01/31Thu8
1Paul2021/01/012021/01/31Fri8
1Paul2021/01/012021/01/31Sat0
1Paul2021/01/012021/01/31Sun0
1Paul2021/02/012021/12/31Mon8
1Paul2021/02/012021/12/31Tue8
1 Paul2021/02/012021/12/31Wed8
1 Paul2021/02/012021/12/31Thu8
1 Paul2021/02/012021/12/31Fri0
1 Paul2021/02/012021/12/31Sat0
1 Paul2021/02/012021/12/31Sun0
...     

 

In my load script I have generated a table that contains the field "Date" with all dates from 2021/01/01 to 2021/12/31  and the field "Weekday". This calendar is linked to the table above by sharing the field "Weekday".

In my visualisation I have a straight table with the dimensions "Date" and "Name" and the intended measure (sum of "hours" for that day):

DateNameWeekdayHours
2021/01/01PaulFri8
2021/01/02PaulSat0
2021/01/03PaulSun0
2021/01/04PaulMon16
...   

 

Obviously, I want Qlik Sense to recognize that for the specific date "2021/01/04" the first values of hours (=8) with the "ValidUntil"="2021/01/31" is relevant, whereas for specific dates after Jan 31, the other value (=0) is relevant.

Can this be done with set analysis in the visualization? Or do I have to make a complete table of all days with all hours for all employees in my load script? I have tried both, but to no avail.

Any help with this issue is highly appreciated! Many thanks in advance!

Tobi

1 Solution

Accepted Solutions
chrismarlow
Specialist II
Specialist II

Hi,

How about trying;

Sum(if(Date>=ValidFrom and Date<=ValidUntil,Hours,Null()))

Cheers,

Chris.

View solution in original post

2 Replies
chrismarlow
Specialist II
Specialist II

Hi,

How about trying;

Sum(if(Date>=ValidFrom and Date<=ValidUntil,Hours,Null()))

Cheers,

Chris.

TobiasTebben
Contributor III
Contributor III
Author

Thanks a lot! That was way easier than I expected. In the past, I have learned to avoid if statements in sums and use set analysis instead. But in this case, "if" does the trick! 🙂