Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Do While loop in script for monthy totals

Hi

Not sure where to start on this one.

Want to end up with the straight Table examples 1 and 2, but with the data calculated in the Script.

Straight Table example 1                          ID - A
14-0114-0214-0314-0414-0514-06Total
Planned Hours5101015101060
Actual Hours101512 37
Remaining Hours 3101023

Straight Table example 2                          ID - B
14-1114-1215-0115-0215-03 Total
Planned Hours100200200200200 900
Actual Hours 250 250
Remaining Hours 50200200200 650

Have Tasks and Resource which is combined into a ID as per ID - A and ID - B

For each ID there are Planned hours per Year-Month to complete the Task & Actual hours they have booked against the task per Year Month

What I need to calculate in the script is the Remaining Planned hours per Year – Month for each ID.

The remaining Planned hours per month cannot be greater than originally planned hours per Month.

As I start off with 5 million rows of raw data as it is stored in days in or ERP system. I have summed this up into a number of tables; the main ones I would use would be Planned Monthly Table and Actual Total Table as shown.

The Planned Monthly Table is sorted by ID and Year Month and has Row No, Total No Months and Total Planned hours.

Planned  Monthly Table
IDYear MonthPlanned HoursRow NoNo of MonthsTotal Planned Hours
A14-0151660
A14-02102660
A14-03103660
A14-04154660
A14-05105660
A14-06106660
B14-1110075900
B14-1220085900
B15-0120095900
B15-02200105900
B15-03200115900

The Actual Total Table just has the ID and the Total Actual Hours. There are other detailed tables but didn’t think they would be wanted demonstrate this example.

Actual Total Table
ID Total Actual
A 37
B

250

My thoughts were to calculate the delta between Total Planned and Total Actual (A = 23) (B = 650)

Then loop through each Month starting at the last month deducting the planned hours from the remaining hours, until the remaining hours are zero, then loop to the next ID. Some ID’s could be over 120 months (10 Years)

A =       23 – 10 = 13

            13 – 10 = 3

            3

B =       650 – 200 = 450

            450 – 200 = 250

            250 – 200 = 50

            50

Sometimes the Actual > than planned so I would filter the table first so I don’t have to loop these then combine them later.

Hope all this makes sense I know this isn’t a 5 minute answer but need some help putting the loop together and moving form 1 ID to the next. So any help would be much appreciated.

Thanks

Mark

11 Replies
Not applicable
Author

Are ok made the column's invisible did't know you could do that.

So on your expression

SUM (TOTAL <ID> [Planned Hours])

The  Planned Hours seems to be reference the expression label instead of the field name, am correct. ? If so

how do you know if you are refering to the lable or the field name

Sorry for all the questions just a bit new to this.

Thanks

Mark

petter
Partner - Champion III
Partner - Champion III

The columns have precedence over field names - but you are right - it is wise to keep the labels with different names than the fields ... or the labels will shadow/hide/redefine the fields that have the same name...