Moving Range calculation for I-MR control chart

peter789

Board Regular
Joined
Nov 20, 2016
Messages
130
As the next step of my control chart project I realise I need to calculate the average of the Moving Range of a group of values in my Pivot Table.
Wikipedia defines the calculation formula here:

https://en.wikipedia.org/wiki/Shewhart_individuals_control_chart

As a first step I have created an Index column in my data using Power Query. Next I tried to test the use of EARLIER to find the minimum of one value and its neighbour in the next row. However this is where it gets stuck.
Any help with the measure I am using would be appreciated please or advice as to whether I should be taking a different tack. I have been reluctant to try and create calculated columns in my data source as just even adding the index column has increased the file size by 20%.
The measure I've tried is:

=CALCULATE(MIN(QryAnalysis[Value]),FILTER(QryAnalysis,QryAnalysis[Oxide]=EARLIER(QryAnalysis[Oxide]) && QryAnalysis[Index]=EARLIER((QryAnalysis[Index]) && QryAnalysis[Index]=EARLIER(QryAnalysis[Index])+1)))

The error is:
"This formula is invalid or incomplete: 'Calculation error in measure 'QryAnalysis'[Minimum of two values]: EARLIER/EARLIEST refers to an earlier row context which doesn't exist.'. "

My Pivot Table looks like:
Oxide
Na2O %
Average Value
Sample DateIndexAmber
03/04/2017
13295011.97
10/04/2017
13295112.00
18/04/201713295211.96
24/04/201713295312.09
02/05/201713295412.11
08/05/201713295512.07
15/05/201713295612.08
22/05/2017
13295712.08
29/05/2017
13295811.98

<colgroup><col><col><col></colgroup><tbody>
</tbody>

Should I plough on? My next measure would be to work out the Max, then AVERAGEX MAX- MIN.
 
Code:
Average Moving Range Selected=
 VAR
varMR=[Max of last two]-[Min of last two] 

RETURN
 IF(ISBLANK( [Moving Range] ),
    BLANK(),
    SUMX(
        ALLSELECTED ( QryAnalysis[Sample Date] ),
        varMR
    )
)
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Unfortunately:

Sample DateColour GroupAverage ValueAverage Selected valuesStarting IndexMin of last twoMax of last twoMoving RangeAverage Moving Range Selected
02/05/2017Flint11.7911.93135072
05/05/2017Flint11.8711.9313507211.7911.870.08194.64
09/05/2017Green12.2012.24135074
10/05/2017Green12.2112.2413507412.212.210.0124.33
15/05/2017Green12.3012.2413507412.2112.300.09218.97
19/05/2017Flint12.0211.9313507212.0212.300.28681.24
22/05/2017Flint12.0211.9313507212.0212.020.000.00
24/05/2017Flint11.9611.9313507211.9612.020.06145.98
29/05/2017Flint11.9711.9313507211.9611.970.0124.33
06/06/2017Flint11.8411.9313507211.8411.970.13316.29
12/06/2017Flint11.9611.9313507211.8411.960.12291.96
19/06/2017Flint11.9411.9313507211.9411.960.0248.66
26/06/2017Flint11.9011.9313507211.911.940.0497.32

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Well that was pretty dumb as that's exactly what I just said wouldn't work. I am not sure I can understand why the outputs are what they are in that column so not sure my fix below is going to help.

Code:
Average Moving Range Selected=
IF(ISBLANK( [Moving Range] ),
    BLANK(),
    SUMX(
        ALLSELECTED ( QryAnalysis[Sample Date] ),
        CALCULATE ( [Max of last two]-[Min of last two] )
    )
)

What do you get from COUNTROWS ( QryAnalysis[Sample Date] ), out of interest? You may want to post another thread as you are beyond my skill level and maybe no one else is reading this at this point.
 
Upvote 0
Sorry, I meant COUNTROWS ( ALLSELECTED ( QryAnalysis[Sample Date] )) when added in your table.
 
Upvote 0
I'm fairly sure that's done it! (I've changed SUMX back to AVERAGEX as I was only using the Sum to see what was happening)
Results:
Sample DateColour GroupAverage ValueAverage Selected valuesStarting IndexMin of last twoMax of last twoMoving RangeAverage Moving Range Selected
02/05/2017Flint11.7911.93135072
05/05/2017Flint11.8711.9313507211.7911.870.0800.082
09/05/2017Green12.2012.24135074
10/05/2017Green12.2112.2413507412.212.210.0100.050
15/05/2017Green12.3012.2413507412.2112.300.0900.050
19/05/2017Flint12.0211.9313507212.0212.300.2800.082
22/05/2017Flint12.0211.9313507212.0212.020.0000.082
24/05/2017Flint11.9611.9313507211.9612.020.0600.082
29/05/2017Flint11.9711.9313507211.9611.970.0100.082
06/06/2017Flint11.8411.9313507211.8411.970.1300.082
12/06/2017Flint11.9611.9313507211.8411.960.1200.082
19/06/2017Flint11.9411.9313507211.9411.960.0200.082
26/06/2017Flint11.9011.9313507211.911.940.0400.082

<colgroup><col style="mso-width-source:userset;mso-width-alt:3291;width:68pt" width="90"> <col style="mso-width-source:userset;mso-width-alt:3876;width:80pt" width="106"> <col style="mso-width-source:userset;mso-width-alt:3035;width:62pt" width="83"> <col style="mso-width-source:userset;mso-width-alt:2706;width:56pt" width="74"> <col style="mso-width-source:userset;mso-width-alt:3693;width:76pt" width="101"> <col style="mso-width-source:userset;mso-width-alt:2377;width:49pt" width="65"> <col style="mso-width-source:userset;mso-width-alt:2998;width:62pt" width="82"> <col style="mso-width-source:userset;mso-width-alt:2669;width:55pt" width="73"> <col style="mso-width-source:userset;mso-width-alt:3364;width:69pt" width="92"> </colgroup><tbody>
</tbody>

I didn't run a COUNTROWS but I could see all the figures were being multiplied by 2433. I guess this was the number of Sample Dates being found when CALCULATE removed the higher level Pivot table filters operating that I haven't shown in my examples (YEAR, MONTH, Production Facility). I'm slightly reluctant to undo the latest changes to find out exactly; I hope you don't mind. You've certainly shown me a couple of uses of ALLSELECTED within an aggregate function that I hadn't read about, firstly qualifying the table name by column and secondly, what I still don't understand, is using SUMX without a Table name.
Many thanks again.
 
Upvote 0

Forum statistics

Threads
1,217,155
Messages
6,134,937
Members
449,897
Latest member
andrew3650

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top