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: 
wcushy
Contributor
Contributor

How to ignore values when a Sum() reaches a certain limit

Hi

I am writing a report that calculates how many hours an individual works on a given day, but want to ignore all remaining values once the sum of those hours reaches 160. I just don't know how to do this in either a select or load statement (I don't want to do this within a chart function).

The data needs grouping by employee number. Example data below. I only want the data for the first 23 rows of Employee 53 but all the rows for employee 56.

Anybody have any idea how best to do this. my data is stored in a .XLSX file.

     

Emp NoForenameSurnameDateHours
53JoeBloggs01/01/20158
53JoeBloggs02/01/20158
53JoeBloggs17/02/20158
53JoeBloggs18/02/20158
53JoeBloggs19/02/20158
53JoeBloggs16/03/20154
53JoeBloggs02/04/20158
53JoeBloggs05/04/20158
53JoeBloggs04/05/20158
53JoeBloggs07/05/20154
53JoeBloggs22/05/20154
53JoeBloggs25/05/20158
53JoeBloggs26/05/20158
53JoeBloggs27/05/20158
53JoeBloggs28/05/20158
53JoeBloggs29/05/20158
53JoeBloggs10/07/20154
53JoeBloggs24/07/20154
53JoeBloggs17/08/20158
53JoeBloggs18/08/20158
53JoeBloggs19/08/20158
53JoeBloggs20/08/20158
53JoeBloggs21/08/20154
53JoeBloggs23/08/20158
53JoeBloggs24/08/20158
53JoeBloggs25/08/20158
53JoeBloggs26/08/20158
53JoeBloggs27/08/20158
53JoeBloggs31/08/20158
53JoeBloggs30/09/20154
53JoeBloggs28/10/20158
53JoeBloggs29/10/20158
53JoeBloggs06/11/20158
56FredBloggs31/12/20148
56FredBloggs01/01/20158
56FredBloggs30/03/20158
56FredBloggs31/03/20158
56FredBloggs01/04/20158
56FredBloggs02/04/20158
56FredBloggs03/04/20158
56FredBloggs06/04/20158
56FredBloggs03/05/20158
56FredBloggs24/05/20158
56FredBloggs20/07/20158
56FredBloggs21/07/20158
56FredBloggs22/07/20158
1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can calculate a cumulative hours field and use that in a where clause in a preceding load:

Data:

LOAD * Where CumulativeHours <= 160;

LOAD *, If([Emp No]=Previous([Emp No]),rangesum(Hours, Peek(CumulativeHours)),Hours) as CumulativeHours;

LOAD [Emp No], Forename, Surname, Date, Hours FROM ...source...;

If your source data isn't ordered by employee and date then you first need to create a table that sorts the data:

Temp:

LOAD [Emp No], Forename, Surname, Date, Hours FROM ...source...;


Data:

LOAD * Where CumulativeHours <= 160;

LOAD *, If([Emp No]=Previous([Emp No]),rangesum(Hours, Peek(CumulativeHours)),Hours) as CumulativeHours;

LOAD [Emp No], Forename, Surname, Date, Hours

Resident Temp

Order By [Emp No], Date;

Drop Table Temp;



talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You can calculate a cumulative hours field and use that in a where clause in a preceding load:

Data:

LOAD * Where CumulativeHours <= 160;

LOAD *, If([Emp No]=Previous([Emp No]),rangesum(Hours, Peek(CumulativeHours)),Hours) as CumulativeHours;

LOAD [Emp No], Forename, Surname, Date, Hours FROM ...source...;

If your source data isn't ordered by employee and date then you first need to create a table that sorts the data:

Temp:

LOAD [Emp No], Forename, Surname, Date, Hours FROM ...source...;


Data:

LOAD * Where CumulativeHours <= 160;

LOAD *, If([Emp No]=Previous([Emp No]),rangesum(Hours, Peek(CumulativeHours)),Hours) as CumulativeHours;

LOAD [Emp No], Forename, Surname, Date, Hours

Resident Temp

Order By [Emp No], Date;

Drop Table Temp;



talk is cheap, supply exceeds demand
wcushy
Contributor
Contributor
Author

Thanks Gysbert.

This does work, but not if i have a Qualify statement before the load expression. I have found a workaround to it though so it is now working for me.

Just got to look at selecting a date range based on selected date now with in my report.

Regards

Wayne