
Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 8, 2014 6:31 AM (in response to Daniel Gargiulo )Hi Daniel
Interesting challenge! I suspect this might be something best tackled in the script, will have a look later on tonight
Erica

Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 8, 2014 7:48 PM (in response to Erica Whalley)Thanks Erica, i look forward to seeing how you go.


Re: QlikView Experts: Control Chart Challenge
Paul Tuyls Jan 8, 2014 6:49 AM (in response to Daniel Gargiulo )Dear,
I also looked into the document and indeed very interesting challenge but i'm a bit confused about the correct/wanted result.
Could you repost the Excel after you added a collumn with the correct/wanted average per line ? So I can see where it changes and how it is calculated.
Most of the time a Excel with the correct data brings 50% of the sollution to these 'challenges'.
Paul

Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 8, 2014 2:25 PM (in response to Daniel Gargiulo )Hi Paul,
Thanks for the interest in the challange.
I have attached a new Excel document with some of the working, note in this example i am only checking for points above the line however if we can resolve the issue for points above the line we will be able to also apply it to points below the line. Please also note a lot of this is done manually in my example eg having to identify the 9th point and then restarting the running average in a new column. Hopefully this is clearer as to desired outcomes. Just let me know if there is anything else.
Please note that we need to be comparing each data point to a RUNNING average.
Dan

Data Average Changes V2.xls 74.0 K

Re: Re: QlikView Experts: Control Chart Challenge
Paul Tuyls Jan 8, 2014 7:10 PM (in response to Daniel Gargiulo )Hi,
I think the Excelsolution is not far away.
Attached is a Excel with the same results as you gave me but I still have to copy 2 columns and manualy activate the formula.
I don't think it is a good moment to look into the Excel, but I would ask you if you could give me a new list of data (only Date + Data is OK, no chart, no correct figures) and I will use the formules to predict the results. After that it will be up to you to check these and if this is OK I think we can continue to Qlikview.
PS: I don't think it is possible to solve the challlange with formules, but will have to use the script I suppose, and that could slow down the load. Are we talking about great number of records ?
PS2 : Erica if you find the solution first, please do NOT say it was easy, it would ruin my week
Paul

Data Average Changes V3.xls 98.5 K

Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 8, 2014 7:48 PM (in response to Paul Tuyls)Hi Paul,
This is definitely another step closer.
I have attached another spreadsheet with new data. The first tab is the same data as before however with no chart and extra columns. The second sheet i have modified the records in the data column.
The data sets will not be large so load times should not be an issue. My only concern with doing this in the script is that the chart will not be dynamic for example if we wanted to filter for a particular year or region. However if we can do it in the script that is still better than manually in excel.
Thanks again,
Dan

New Data Average Changes.xls 37.5 K

Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Dave Riley Jan 9, 2014 4:16 AM (in response to Daniel Gargiulo )Here's a solution in script, I think, using some random data, but it proves the method.
// Sample Data  row order will need to be accurate to ensure correct calculation later
Data1:
Load
Rowno() & ':' & ID & ':' & Value as UID,
* inline [
ID, Value
1, 85
2, 74
3, 83
4, 62
5, 81
6, 80
7, 79
8, 78
9, 77
10, 86
11, 85
12, 86
13, 88
14, 89
15, 90
16, 91
17, 91
18, 92
19, 86
20, 88
21, 98
22, 97
23, 98
24, 97];
Let SeedSample = 3; //specify how many rows to sample to start off average
Let RunPeriod = 8; //specify how many consecutive periods should trigger a change
FirstAvg:
Load Avg(Value) as SeedAvg resident Data1 where RecNo() <= $(SeedSample);
Let Seed = peek('SeedAvg');
Drop Table FirstAvg;
let runningAvg = 0;
let runningSum = 0;
let AvgSequence = 0;
let LastAvg = 0;
let seq = 1;
let AvgRun = 0;
//Loop over each row
for r = 1 to NoOfRows('Data1')
let runningAvgPrev = runningAvg;
let runningSum = (runningSum + SubField(FieldValue('UID',$(r)),':',3));
let runningAvg = runningSum / seq;
if runningAvg >= Seed then
let AvgSequence = 1;
else
let AvgSequence = 1;
end if;
if AvgSequencePrev=AvgSequence then
let AvgRun = AvgRun + 1;
ELSE
let AvgRun = 1;
end if;
let AvgSequencePrev = AvgSequence;
if AvgRun = $(RunPeriod) then
let seq = 1;
let runningSum = SubField(FieldValue('UID',$(r)),':',3);
let runningAvg = runningAvgPrev;
let Seed = runningAvg;
let AvgRun = 1;
end if;
let seq = seq + 1;
RunningAvgs:
Load
$(r) as ID,
$(runningSum) as RunningSum,
$(runningAvg) as RunningAvg,
$(AvgSequence) as AvgSequence,
$(AvgRun) as AvgRun,
$(Seed) as ActiveAvg
autogenerate 1;
next r;Try copying it into a new doc and see how it works.
flipside

Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 9, 2014 8:26 PM (in response to Dave Riley)Hi Flipside,
Thanks for responding. I have put your script into a QVW and input the data (see QVW attached). It seems to be recalculating the average every 8 points (or what ever the 'runperiod' is set to). What we require to trigger a change in the average is 9 (runperiod) consecutive points above the average. I feel like your script and the concept of a loop approach is another step closer with one of the remaining piece of the puzzle for this approach is getting the step up trigger correct.
I look forward to seeing if we crack this.
kind regards,
Dan

Flipside eg new numbers.qvw 202.8 K

Re: QlikView Experts: Control Chart Challenge
Dave Riley Jan 10, 2014 4:25 AM (in response to Daniel Gargiulo )Hi Dan,
Try changing the line ...
if AvgRun = $(RunPeriod) then
to ..
if AvgRun > $(RunPeriod) then
It just depends whether you want the step up to occur ON the RunPeriod threshold or the period AFTER it.
flipside

Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 11, 2014 3:30 PM (in response to Dave Riley)Hi Flipside,
I have made this change and we are still having the average calculated at regular intervals instead of only when there are 9 consecutive points above the running average.
I think what we are missing is that every loop we need to re compare the previous 9 'Values' to the new 'RunningAvg' to see if they are above it or not. If they are all above the new running average this would trigger a change.
Again i feel like this approach is close.
Thanks,
Dan

Re: QlikView Experts: Control Chart Challenge
Dave Riley Jan 13, 2014 4:37 AM (in response to Daniel Gargiulo )
Hmm, I'm not entirely sure what you need. My script changes the ActiveAvg when it finds x consecutive values above (or x consecutive values below) its value. Once ActiveAvg is reset it then compares this new value with the average reset from the next row of data (so it will be that row's data value divided by 1) and so on until it finds another run of x consecutive values above (or below) its new value. In your example your data looks like it has an increasing trend so the average is continually increasing. Try putting in a sequence of some lower values mid way to see if it drags the average down.What I would suggest however is that you build up a script starting as follows so you can be sure the logic is as you require it ...
1. Ensure your data has a unique field in it. I have created the field UID. This is so we can guarantee that the FieldValue returns the rows without skipping any values.
2. Build up a table called RunningAvgs row by row in a loop starting with totals only. Your first script might look like this ...
let runningSum = 0;
for r = 1 to NoOfRows('Data1')
let runningSum = (runningSum + SubField(FieldValue('UID',$(r)),':',3));
RunningAvgs:
Load
$(r) as ID,
$(runningSum) as RunningSum
autogenerate 1;next r;
You can compare the calculated values with an excel spreadsheet to see if the logic is as you require, and moreover, that the rows are being called in the correct sequence.
3. Add in logic to calculate the average. At this point you could just divide the RunningSum by r, but because you want to reset the average later on, you'll need to use a second counter, seq. You can't use r because it would break the loop sequence and/or cause an eternal loop. Remember to increase the seq counter within the loop.
4. Once you have your RunningAvg, you can start comparing it to the Seed average values or Data values to determine whether it is above or below (1, 1), and then on the next loop check if there is a sequence of above/below values and increase the sequence counter.
It's easier to understand when you've built up the logic from the ground.
Hope this helps
flipside





Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Paul Tuyls Jan 9, 2014 5:41 AM (in response to Daniel Gargiulo )Hi,
Enclosed the new data with the Excelformula.
The first set is givin same result, the second has to be checked.
Did you test flipside's solution ? I'am very curious but I have no time for the moment to test it myself.
Perhaps later on.
flipside, you have already my respect
Paul

New Data Average Changes V2.xls 100.5 K

Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 9, 2014 8:17 PM (in response to Paul Tuyls)Hi Paul,
The second sheet is very close to be being perfect. The only thing is that once the rule has been meet it can not be meet again until there has been at lease another 9 points. I have reattached it and highlighted in red where this rule would come into effect. I am not sure how/where we add the rule that says if the average has restarted then needs to be at least 9 points away from when it started but i think once we get it we would have automated it in excel at least.
Thanks again for all your help to date

New Data Average Changes V4.xls 103.5 K

Re: Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Paul Tuyls Jan 12, 2014 7:50 PM (in response to Daniel Gargiulo )Hi,
Hope you are still interested in a Excelsolution because I did not follow the QlikViewsolution yet ?
The previous Excel was correct, but I had to copy the calculated formulas manualy to 2 columns.
In this new version I used the INDERECTExcelfunction (new to me) so that you only have to give columns A and B and the average will show up in column R (you can hide all the other columns).
I also added 9 columns to test if the data is decreasing, but I think in the current sample there is no such point.
Could you confirm the correct results (and test other series of data) ?
If it's OK, we have a tool to compare it with the QVresults, and I can start looking into it (but I think the others are more skilled in QV than me !!)
Paul

Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 13, 2014 12:13 AM (in response to Paul Tuyls)HI Paul,
I can confirm that the excel spreadsheet is correct and also works for decreasing values. I am very impressed with your excel knowledge. This is definitely another step closer which is excellent.
Now how to achieve in QV is the next interesting challange?
Thanks
Dan







Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 9, 2014 6:10 PM (in response to Daniel Gargiulo )Hi Daniel
It is possible in the chart.
If you set 2 more expressions as counters
R2CUMA_revCT: how many rows above untill the next time there is a run of 8
=if(isnull(below([R2CUMA_revCT])),0,
if([R2CUMA]=8,0,below([R2CUMA_revCT])+1))
R2CUMA_abvCT: how many rows below until the next time there is a run of 8
=if(isnull(above([R2CUMA_abvCT])),0,
if([R2CUMA]=8,0,above([R2CUMA_abvCT])+1))
Then use these in a rangesum calculation to get the average for "R2CUMA_revCT" rows below and "R2CUMA_abvCT" rows above.
Average2:
=rangesum(above(Data,R2CUMA_revCT,R2CUMA_revCT+R2CUMA_abvCT))
/RangeCount(above(Data,R2CUMA_revCT,R2CUMA_revCT+R2CUMA_abvCT))
Example attached. NB: the shift is barely detectable, but still there!
It's not quite there yet, but something to work from!
Erica

Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 9, 2014 6:45 PM (in response to Erica Whalley)You can easily change the counter expressions to reset when they get to points below the line, as well as above:
=if(isnull(below([R2CUMA_revCT])),0,
if([R2CUMA]=8 or [R2CUM]=8,0,below([R2CUMA_revCT])+1))
Where R2CUM is the equivalent expression that tests for points below the line.
Erica

Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 9, 2014 8:48 PM (in response to Erica Whalley)Thanks Erica. This also sounds like it is a step closer and if we can do it in the chart that would be AMAZING!!! In your example it seems that the average is not what I would have expected though. I would have expected it to be around 91% for starters and then jump to around 94% on the 01/11/13 to the end of the period. This is based on 9 consecutive points. Again i feel like the concept is there and it is just a matter of tweaking to get it right.
I have to head to a wedding now so don't have time to fully understand the new fields sorry but I will hopefully get a chance over the weekend.
thanks
Dan

Re: Re: Re: Re: Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 10, 2014 3:53 AM (in response to Daniel Gargiulo )Hi Dan
It's probably because there issues with the Above function  for some reason rangecount(above(Data,0,30) is returning 17, not 30! I think it because the field is dynamic ie $(variable) rather than the field name... the counters also need to be tweaked to recognise the end of a run rather than just 8 steps into it
Anyway enjoy your weekend, and the wedding
Regards,
Erica

Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 12, 2014 6:23 PM (in response to Erica Whalley)Hi Dan
If you change the counters to this:
R2CUMA_revCT
=if(isnull(below([R2CUMA_revCT])),0,
if(([R2CUMA]<=8 and Below([R2CUMA])=0) or ([R2CUM]<=8 and Below([R2CUM])=0),
0,
below([R2CUMA_revCT])+1))
R2CUMA_abvCT
=if(isnull(above([R2CUMA_abvCT])),0,
if((above([R2CUMA])<=8 and [R2CUMA]=0) or (above([R2CUM])<=8 and [R2CUM]=0),
0,above([R2CUMA_abvCT])+1))
Then they will commence at the end of a run of 8 or more negative/ positive values.
I'm losing the plot with the Range and above/below functions though when it comes to the average. Even just a simple expression rangecount(above(total [Data],30,30)) is returning strange values. (it should return 30  because that is the range that is returned by the above function...!)
Any ideas on that anyone?
Erica




Re: QlikView Experts: Control Chart Challenge
Erica Whalley Jan 12, 2014 6:40 PM (in response to Daniel Gargiulo )Okay  this works, but only as a temporary fix as either I don't fully under stand the above / below functions, or there maybe a bug.
I've replaced the "average 2" formula with a function which uses the below() function if it is at the start of a run (seems to work fine when offset=0) otherwise, steal the value above it!
=if(R2CUMA_abvCT=0,
rangesum(below(Data,0,R2CUMA_revCT+R2CUMA_abvCT))
/(R2CUMA_revCT+R2CUMA_abvCT),
above([Average 2]))
Erica

Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 13, 2014 1:15 AM (in response to Erica Whalley)Hi Erica,
Thanks again for having another crack at this however the average should be jumping up on 1/09/11 (assuming 9 consecutive points).
I am pretty sure in your example it is jumping up later because 'R2CUMA_abvCT' and 'R2CUMA_revCT' are linked to 'R2CUMA' and 'R2CUM' which are both linked to the overall 'Average'. We really need to be testing each data point against a cumulative average, a good example is Pauls excel document. I have reattached this with the original data for comparison purposes.
I think what we need is:
 a cumulative average field. Then:
 R2CUMA and R2CUM to be changed so at each data point they check the previous 9 data points against the current 'CumAvg' and come up with the number that meet the criteria. Your other logic should then flow from there. My understanding of how the above and below is far less than yours but hopefully it makes sense what i THINK we need to do.
From what i can tell the other functionality seems to be working.
thanks again,
dan

Re: QlikView Experts: Control Chart Challenge
Christian Lauritzen Jan 15, 2014 2:13 AM (in response to Daniel Gargiulo )Daniel,
This is an interesting problem. There are great many clever approaches above. I could not help but to give it a try, so here is another variant. I used two counters, one that keeps track of consecutive points above average and one for points below. Then the Average formula checks these counters and updates the average when it is time.
The values is consistent with my manual check in Excel, but the average adjustments points differ from the picture in Excel. Maybe I misunderstood the logic. Anyhow, here is the solution.
Expression for Counter to track points above average (CounterH):
=if(Above(if(Data>Average,1,0))=1,mod(Above(CounterH),8)+1,0)
Expression for Counter to track points above average (CounterL):
=if(Above(if(Data<Average,1,0))=1,mod(Above(CounterL),8)+1,0)
The mod function secures that the counter is reset after 9 consecutive points. The Counters need to be set as invisible and also put on the right axis.
Average starts with an average of all data, and a change kicks in when any of the counters reach 8 (08 = 9 points) and creates an average of points below.
=if(RowNo()<=8, Avg(Total Data),
if(CounterH<8 AND CounterL<8, Above(Average,1),rangesum(Below(sum(Data),0,NoOfRows()RowNo()))/ (NoOfRows()RowNo()) ))
Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 14, 2014 8:58 PM (in response to Christian Lauritzen )Hi Christian,
Thanks for replying to the problem, it is great to see yet another approach. I am looking forward to seeing what one will finally crack it.
I think the reason it is different to the picture in excel is that we should be using a cumulative average to compare to each data point right from the start. I think currently it is only doing this after there has been 8 points above the TOTAL average.
Please note that we are also looking for 9 points above or below the average.
I look forward to hopefully seeing if a revised version is possible.
Thanks
Dan
Re: QlikView Experts: Control Chart Challenge
Christian Lauritzen Jan 15, 2014 1:54 PM (in response to Daniel Gargiulo )Just Googled Control Chart. http://www.wikihow.com/CreateaControlChart
The graph is outofcontrol if any of the following are true:
 Any point falls beyond the red zone (above or below the 3sigma line).
 8 consecutive points fall on one side of the centerline.
 2 of 3 consecutive points fall within zone A.
 4 of 5 consecutive points fall within zone A and/or zone B.
 15 consecutive points are within Zone C.
 8 consecutive points not in zone C.
Zone A is +/ 1 std deviation, Zone B is 2 and Zone C is 3 std dev.
Do you wish all these rules to apply when readjusting the mean?

Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 15, 2014 9:44 PM (in response to Christian Lauritzen )Hi Christian,
At this stage we are only focused on the rule of the 9 consecutive points above the cumulative average as the trigger to readjust the mean. Once this has been triggered the cumulative average would begin again with the search for another 9 points above or below the mean. Does this makes sense? If you see Paul's Excel example above this provides a good overview of the desired result.
Thanks again,
Dan

Re: QlikView Experts: Control Chart Challenge
Christian Lauritzen Jan 16, 2014 6:41 PM (in response to Daniel Gargiulo )Daniel,
I gave this some more thought (honestly, it bugged me a lot!) and I am see this challenge is a bit trickier than it seemed to be at first glance. It has a built in trap. I'll explain how.
The rule:
Generate an average for a section. The section ends when 9 consecutive points are above or below the section average. The average should be based on all points in the section, excluding the 9th point. The next section begins at the 9th consecutive point.
Problem:
The rule is a sort of recursive logic, where you have to iterate the size of each section until the end of data or until 9 consecutive points. With this rule, there are data sets cannot be resolved due to that logic loops that occur. With your specific data set you do not encounter the loop situation. You do however with the set below.
Example:
The data set below triggers the logic loop. As the first section is expanded to find the 9 points in a row that are below or above average, no such pattern is found until you include point 21  a very high value.
Suddenly, the first 9 points in the section are below the cumulated average. The section should then end at point 8. You need to recalculate the average up until point 8. However, now you don't find any 8 consecutive points below or above average anymore. Not until the section once again is expanded until point 21. And so it goes…
You have a logical loop that never ends.
Since there are control diagrams with changing averages out there, they should have a different set of rules.
Sorry to not be able to help you more.
/Christian
Data Set:

Re: Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 18, 2014 3:33 PM (in response to Christian Lauritzen )Hi Christian,
Thanks for taking another look at this and apologies for the delay in responding, i needed a couple of days not looking at this to keep my sanity!!!
I have taken your data set and put it into Pauls excel solution (see attached), it seems to calculate as expected in excel. Note the 21st point does not actually trigger the change as the data point (100000000) is still above the average even though all others are below. It does get triggered on line 30 though when (100000000) is no longer compares part of the 9 consecutive points.
You noted "The average should be based on all points in the section, excluding the 9th point." Please note the average actually includes the 9th consecutive point.
Based on the above do you think this is something you could take another look at? I feel like your initial approach was close and I think my notes here hopefully mean recursive logic is no longer an issue.
Thanks
Dan







Re: QlikView Experts: Control Chart Challenge
Daniel Gargiulo Jan 19, 2014 2:23 AM (in response to Daniel Gargiulo )POSSIBLE SOLUTION
Hi All,
I think we may have a solution, please see QVW attached. This basically takes the logic of Paul's spreadsheet and puts it into a QlikView table/chart. If you have a chance it would be great if people could try and pick some holes in the solution to check it holds up.
I am also intrigued to see if people have any suggestions for:
1. Is there a better way to Count the number of points that are above or below the CumAvg instead of all the Pos. Line1 and Neg Line 1? If so we may be able to allow users to choose the number of consecutive points above ro below the average with a variable.
2. How to Add further rules as per Ericas original Control Chart.
a) Highlight the points that make up values that are above/below the average to trigger the step change.
b) Highlight series of points that are increasing and decreasing.
My fingers are crossed this is going to hold up under cross examination!!!! Thank you all again for soooooo much help. This would have got no where with out so many ideas bouncing around. I had all but given up hope that this was possible.
Erica, if this does end up a solution then please feel free to write it up in your blog.
Thanks again,
Dan

Re: QlikView Experts: Control Chart Challenge
Graham Fletcher Aug 29, 2017 7:23 PM (in response to Daniel Gargiulo )Been a few years but I found it odd there was no reply here? Are you using this chart Daniel? I've just plugged in my data and it looks really good, seems to be holding up well. I've added in a highlight for the data points that are involved in the run to a step change (though I think you may have found this by now!).
Anyway, thanks for your work on this, it's really helpful. Let me know if you've got any enhancements!
