Meter Point Administration Number#Line Loss Factor Class (LLFC)

{{Short description|Identifier of mains electricity supply point}}

{{Use British English|date=March 2022}}

{{Use dmy dates|date=March 2022}}

A Meter Point Administration Number, also known as MPAN, Supply Number or S-Number, is a 21-digit reference used in Great Britain to uniquely identify electricity supply points such as individual domestic residences. The system was introduced in 1998 to aid creation of a competitive environment for the electricity companies, and allows consumers to switch their supplier easily as well as simplifying administration. Although the name suggests that an MPAN refers to a particular meter, an MPAN can have several meters associated with it,{{cite web|url=http://www.elexon.co.uk/documents/BSC_Panel_and_Panel_Committees/BSC_Panel_Meetings_2006_-_121_-_Papers/121_08.pdf |title=Settlement of Microgeneration Export |author=Elexon |url-status=dead |archiveurl=https://web.archive.org/web/20071009214531/http://www.elexon.co.uk/documents/BSC_Panel_and_Panel_Committees/BSC_Panel_Meetings_2006_-_121_-_Papers/121_08.pdf |archivedate=October 9, 2007 }} or indeed none where it is an unmetered supply. A supply receiving power from the network operator (DNO) has an import MPAN, while generation and microgeneration projects feeding back into the DNO network are given export MPANs.

The equivalent for gas supplies is the Meter Point Reference Number and the water/wastewater equivalent for non-household customers is the Supply Point ID.

Structure

An MPAN is commonly separated into two sections: the core and the top line data. The core is the final 13 digits and is the unique identifier. The top line data gives information about the characteristics of the supply and is the responsibility of the supplier.

The full MPAN is required to be depicted on electricity bills (the boxes on the top and bottom line are generally unaligned).{{cite web | url=http://energylinx.co.uk/mpan.htm | title=MPAN (Meter Point Administration Number) | author=Energy Linx | year=2007 | accessdate=2007-02-22}}

centre

The core data is on the second line, the supplementary data on the first. Only the last digit on the bottom row is the check digit.

= Profile Class (PC){{anchor|PC}} =

The first two digits of a full MPAN reflect its profile class.{{cite web|url=http://www.elexon.co.uk/ELEXON%20Documents/bscp516_v7.0.pdf |author=Elexon |title=BSCP516 – Balancing and Settlement Code |accessdate=2011-07-25 |url-status=dead |archiveurl=https://web.archive.org/web/20120319031827/http://www.elexon.co.uk/ELEXON%20Documents/bscp516_v7.0.pdf |archivedate=2012-03-19 }}

class="wikitable"
00

| Half-hourly supply (import and export)

01

| Domestic unrestricted

02

| Domestic Economy meter of two or more rates

03

| Non-domestic unrestricted

04

| Non-domestic Economy 7

05

| Non-domestic, with maximum demand (MD) recording capability and with load factor (LF) less than or equal to 20%

06

| Non-domestic, with MD recording capability and with LF less than or equal to 30% and greater than 20%

07

| Non-domestic, with MD recording capability and with LF less than or equal to 40% and greater than 30%

08

| Non-domestic, with MD recording capability and with LF greater than 40% (also all non-half-hourly export MSIDs)

Profile class 00 supplies are half-hourly (HH) metered, i.e. they record electricity consumption for every half hour of every day, and supplies of the other profile classes are non-half-hourly (NHH) metered. A NHH supply must be upgraded to HH where:{{cite web |last=Elexon |title=Change of Measurement Class and Change of Profile Class |date=2015-06-25 |url=https://www.elexon.co.uk/wp-content/uploads/2015/06/change_of_measurement_profile_class_v11.0.pdf |accessdate=2016-07-05 |url-status=dead |archiveurl=https://web.archive.org/web/20160817055349/https://www.elexon.co.uk/wp-content/uploads/2015/06/change_of_measurement_profile_class_v11.0.pdf |archivedate=2016-08-17 }}

{{cquote|Any Metering System where the average of the maximum monthly electrical demands in the three months of highest demand, either in:

:a. the previous twelve months; or

:b. the period since the most recent Significant Change of Demand (whichever is the shorter)

exceeds 100kW.}}

HH data is recorded by the meter and collected by an onsite download, or by remote communication methods such as GSM, SMS, GPRS or telephone line.

Domestic NHH import MPANs always have a profile class of 01 or 02. Domestic NHH export MPANs are allocated a profile class of 08.

= Meter Time Switch Code (MTC) =

The MTC is a 3 digit code that reflects the various registers a meter may have, such as a single rate, day/night split, or a seasonal time of day.{{cite web | url=http://mrasco.com/admin/documents/The_Rough_Guide_To_MTCs.pdf | author=MRASCo | title=The Rough Guide To MTCs | accessdate=2011-02-05 | archive-url=https://web.archive.org/web/20160113042907/http://mrasco.com/admin/documents/The_Rough_Guide_To_MTCs.pdf | archive-date=2016-01-13 | url-status=dead }}{{cite web|url=http://mddonline.elexon.co.uk/mddtable.aspx?tbl=Meter+Timeswitch+Class |author=Elexon |title=Meter Timeswitch Class table |accessdate=2011-08-23 |url-status=dead |archiveurl=https://web.archive.org/web/20110426000854/http://mddonline.elexon.co.uk/mddtable.aspx?tbl=Meter%2BTimeswitch%2BClass |archivedate=April 26, 2011 }}

class="wikitable"

|+ MTC Ranges

001–399DNO specific
400–499Reserved
500–509Codes for related Metering Systems – common across the Industry
510–799Codes for related Metering Systems – DNO specific
800–999Codes common across the Industry

= Line Loss Factor Class (LLFC) =

The Line Loss Factor Class or LLFC{{cite web | url=http://www.elexon.co.uk/glossary/line-loss-factor-classes/ | title=Line Loss Factor Class(es) | authorlink=Elexon | work=Elexon Glossary | accessdate=2013-01-27 }} is an alphanumeric code used to identify the related Distribution Use of System (DUoS) charges for the MPAN. The figure reflects both the amount of distribution infrastructure used to supply the exit point and the amount of energy lost through heating of cables, transformers, etc.

= Core =

The MPAN core is the final 13 digits of the MPAN, and uniquely identifies an exit point. It consists of a two-digit Distributor ID, followed by an eight-digit unique identifier, then by two digits and a single check digit.

== Distributor ID ==

Image:Distribution Network Operators.PNG

Great Britain is divided into fourteen distribution areas. For each area a single company, the distribution network operator, has a licence to distribute electricity.{{cite web |author= |year= |title=MPAN (Meter Point Administration Number) |url=https://www.energylinx.co.uk/mpan.htm |accessdate=23 October 2023 |website=Energylinx}} They effectively carry electricity from the National Grid to the exit points (each having a unique MPAN and a possibility of several meters) where the customers are. The owner of the distribution network charges electricity suppliers for carrying the electricity in their network. Their DNO licensed regions are the same geographic areas as the former nationalised electricity boards.

class="wikitable sortable"

|+ DNOs

ID

! Name

! Operator

! Phone Number

! Market Participant ID{{cite web | last=Elexon | authorlink= | title=Market Participant Role | url=http://www.elexon.co.uk/participating/marketdomaindata/mdd/mddtable.aspx?tbl=Market+Participant+Role | accessdate=2009-12-20}} {{dead link|date=March 2013}}

! GSP Group ID{{cite web |last= |authorlink= |title=GSP Group |url=https://www.elexon.co.uk/bsc/glossary/grid-supply-point/ |accessdate=2025-05-20 |website=Elexon}}

10

| Eastern England

| UK Power Networks

| 0800 029 4285

| EELC

| _A

11

| East Midlands

| National Grid (formerly Western Power Distribution)

| 0800 096 3080

| EMEB

| _B

12

| London

| UK Power Networks

| 0800 029 4285

| LOND

| _C

13

| Merseyside and Northern Wales

| SP Energy Networks

| 0330 10 10 444

| MANW

| _D

14

| West Midlands

| National Grid (formerly Western Power Distribution)

| 0800 096 3080

| MIDE

| _E

15

| North Eastern England

| Northern Powergrid

| 0800 011 3332

| NEEB

| _F

16

| North Western England

| Electricity North West

| 0800 048 1820

| NORW

| _G

17

| Northern Scotland

| Scottish & Southern Electricity Networks

| 0800 048 3516

| HYDE

| _P

18

| Southern Scotland

| SP Energy Networks

| 0330 10 10 444

| SPOW

| _N

19

| South Eastern England

| UK Power Networks

| 0800 029 4285

| SEEB

| _J

20

| Southern England

| Scottish & Southern Electricity Networks

| 0800 048 3516

| SOUT

| _H

21

| Southern Wales

| National Grid (formerly Western Power Distribution)

| 0800 096 3080

| SWAE

| _K

22

| South Western England

| National Grid (formerly Western Power Distribution)

| 0800 096 3080

| SWEB

| _L

23

| Yorkshire

| Northern Powergrid

| 0800 011 3332

| YELG

| _M

In addition to the distribution network operators noted above who are licensed for a specific geographic area, there are also independent distribution network operators (IDNOs). These own and operate electricity distribution networks which are mostly network extensions connected to the existing distribution network, e.g. to serve new housing developments.

Scottish Hydro Electric Power Distribution also provide distribution services in South Scotland as an IDNO and Southern Electric Power Distribution provide IDNO services in all other England and Wales areas. Other IDNOs have no "base" area.{{cite web | url=http://www.ofgem.gov.uk/temp/ofgem/cache/cmsattach/12925_24605.pdf | author=Ofgem | title=Notice under section 11 of the Electricity Act 1989 | accessdate=2007-02-22 | archiveurl=https://web.archive.org/web/20051230010301/http://www.ofgem.gov.uk/temp/ofgem/cache/cmsattach/12925_24605.pdf | archivedate=December 30, 2005}}

class="wikitable"

|+Independent Distribution Network Operators

! ID{{Citation needed|date=October 2023}}

! Name

! Licensee{{cite web | last=Ofgem | authorlink= | title=List of all electricity licensees including suppliers | url=https://www.ofgem.gov.uk/publications/list-all-electricity-licensees-including-suppliers | accessdate=2021-09-21}}

! Market Participant Id

24

| GTC

| Independent Power Networks Limited

| IPNL

25

| ESP Energy

| ESP Energy

| LENG

26

| Energetics / Last Mile

| Last Mile Electricity Limited

| GUCL

27

| GTC

| The Electricity Network Company Ltd

| ETCL

28

| EDF IDNO

| UK Power Networks (IDNO) Ltd

| EDFI (no longer live)

29

!

|Harlaxton Energy Networks Ltd

|HARL

30

!

|Leep Electricity Networks Ltd

|PENL

31

!

|UK Power Distributions Ltd

|UKPD

32

| Energy Assets Networks

| Energy Assets Networks Ltd

| UDNL

33

| EPN

| Eclipse Power Networks Ltd

| GGEN

34

!

| Murphy Power Distribution Limited

| MPDL

35

| Fulcrum Electricity Assets

| Fulcrum Electricity Assets Ltd

| FEAL

36

|Vattenfall Networks

|Vattenfall Network Limited

|VATT

37

|Forbury Assets Limited

|Forbury Assets Limited

|FORB

38

|Indigo Power Limited

|Indigo Power Limited

|INDI

39

|Squire Energy Metering Ltd

|Squire Energy Metering Ltd

|STRK

40

|Utility Assets Limited

|Utility Assets Limited

|UTAL

42

|Advanced Electricity Networks

|Advanced Electricity Networks

|AENL

43

|IDCS Ltd

|IDCS Ltd

|IDCS

45

|Aurora Utilities Limited

|Aurora Utilities Limited

|AURO

46

|Aidien Limited

|Aidien Limited

|AIDI

47

|Vital Energi Power Networks

|Vital Energi Power Networks

|VEPN

48

|E.ON UK Network Assets Limited

|E.ON UK Network Assets Limited

|EONN

MPAN state

The supply identified by the MPAN can be in one of four states: disconnected, de-energised, live, and new.

  • Disconnected: The service cable has been removed and the MPAN will not be reused.
  • De-energised: The service cable is in place, but the fuse has been removed. The meter remains connected to the distribution network, but no electricity can be used.
  • Live: Both the service cable and the fuse are in place. The supply is fully operational.
  • New: A new MPAN has been generated, however, the top line (supplementary data consisting of the Profile Class and Meter Time-Switch Code) is not yet complete. The service cable may or may not be installed.

These terms are by no means standardised. For example, a disconnected supply might be referred to as a 'dead' supply.

Export MPANs

The vast majority of MPANs are import MPANs, where energy is being consumed. However, if a supply exports to the distribution network, then an export MPAN is issued. If a supply both imports and exports, then both an import MPAN and export MPAN are issued.

= Microgeneration =

Formerly, export MPANs required a half-hourly compliant meter to be installed. Since 2003, it has been possible for microgeneration projects, with a capacity of 30 kW or below, to have a non-half-hourly meter to measure export back into the distribution network. Uptake was slow, with the first microgeneration export MPAN being issued in June 2005. Some suppliers may not bother to register the export MPAN in MPAS as the revenue is so small.{{Citation needed|date=March 2022}}

Following the closure of the feed-in tariffs, in January 2020 Ofgem introduced the Smart Export Guarantee (SEG) arrangements, where an export MPAN is allocated to allow a supplier to pay a customer for export of low-carbon energy.{{Cite web |title=Smart Export Guarantee (SEG) |url=https://www.ofgem.gov.uk/environmental-and-social-schemes/smart-export-guarantee-seg |access-date=2022-03-04 |website=Ofgem |language=en}}{{Cite web |date=23 December 2019 |title=Smart Export Guarantee (SEG) Terms and Conditions |url=https://www.ovoenergy.com/pdf/smart-export-guarantee-ts-cs.pdf |access-date=4 March 2022 |website=OVO Energy}}

Export capacity over 30 kW is required to be half-hourly metered. As part of the Marketwide Half Hourly Arrangements (MHHS), all export consumption will be required to be registered and settled on a half-hourly basis.{{Citation needed|date=March 2022}}

Metered Supply Point

The Metered Supply Point (MSP) is the point at which the meter measuring a customer's consumption is located. It is thus also the point at which either the distribution network operator's supply, or the building network operator's lateral cable, terminates and the customer's equipment begins. In order to firmly establish a supply's MSP, the MPAN needs to be associated with a meter serial number.

Although it is common for an MPAN to be associated with one meter serial number, in some cases there is a many-to-many relationship. For example, one meter could be associated with both an import and an export MPAN, or one MPAN could be measured by three separate meters.

Metering Code of Practice

class="wikitable"

|+ Code of PracticeSee {{cite web |url=http://www.elexon.co.uk/bscrelateddocs/codesofpractice/ |title=ELEXON - Codes of Practice |accessdate=2008-11-16 |url-status=dead |archiveurl=https://archive.today/20070813075542/http://www.elexon.co.uk/bscrelateddocs/codesofpractice/ |archivedate=2007-08-13 }}

Code

! Range

! Configuration

COP10

| less than 72 kW

| One HH whole current meter installed. Introduced for February 2009.{{cite web|url=http://www.elexon.co.uk/changeimplementation/ChangeProcess/proposals/proposal_details.aspx?proposalId=777 |title=Change Implementation }}{{dead link|date=May 2016|bot=medic}}

COP5

| less than 1MW

| One HH meter installed.

COP3

| 1MW to 10MW

| Two meters installed, main and check, both recording the same load. The main meter being used for billing.

COP2

| 10MW to 100MW

| Two meters installed as in COP3, but higher-accuracy class meters.

COP1

| > 100MW

| Very few sites in the UK at this level, generally power stations and connections with the National Grid.

Unmetered supplies

It is possible for small predictable supplies to be unmetered.{{Cite web|url=https://www.elexon.co.uk/operations-settlement/unmetered-supplies/|title=Unmetered Supplies|website=ELEXON|access-date=3 January 2019}} Examples are street lights, traffic signals, signs, bollards, telephone kiosks, CCTV and advertising displays.

For an item of equipment to be connected to the distribution network via an unmetered connection, its consumption should typically not exceed 500 watts and it should operate in a predictable manner, with no provision for it to be manually turned on/off at the end user's request. Generally the equipment would either be in operation and taking a supply of electricity 24 hours a day, or be controlled by a photocell, as is often the case for street lights.

It is the customer's responsibility to maintain an accurate and up-to-date inventory of unmetered supplies, and to inform the UMSO (UnMetered Supplies Operator) of all changes to the connected equipment within one month of the change.

Larger local authorities generally have unmetered supplies with a demand over 100kW and are required to trade their unmetered energy on a half-hourly basis. To do so, they employ a meter administrator{{cite web | title=Meter Administrator | author=Power Data Associates Ltd | url=http://www.powerdataassociates.com/unmetered}}{{cite web | title=Meter Administrator | author=ICTIS (UK) Ltd | url=http://www.ictis.net/meter-administrator.htm}} who will use daily data from a photo-electric control unit (PECU) array which is then used to calculate the energy consumption. A PECU array is a device that holds a representative number of the photocells that authority uses on their street lights or traffic signals.{{Cite web|url=https://www.powerdataassociates.com/photo-electric-control-unit-arrays|title=Photo Electric Control Unit Arrays|website=Power Data Associates|access-date=4 March 2022}} By trading energy as unmetered half-hourly the authority will accurately pay for the energy consumed by their declared unmetered equipment, and because the data is downloaded daily the authority will see their energy invoices change throughout the year to represent the changes in the seasonal daily lighting levels.

If, however, the unmetered supplies are being traded as non half-hourly the UMSO undertakes the responsibility to calculate an EAC (Estimated Annual Consumption). This is done using a simple formula which takes into account the circuit watts of the equipment and the annual hours of operation. For example, a piece of equipment that is in use 24 hours per day will have annual hours of 8766. For, say, a CCTV camera rated at 24 circuit watts the EAC would be 210.384kWh, calculated as circuit watts × annual hours divided by 1000. As a result of Ofgem's decision to progress with Marketwide Half Hourly Settlement (MHHS) all new unmetered supplies from April 2024 will be half hourly and existing non half-hourly unmetered supplies will move to half hourly trading during 2024.

If the equipment is street lighting the same process is used for non half-hourly; however, the annual hours will change as each photocell is assigned a set number of annual hours which indicate how and when the lights turn on and off. These annual hours have been set by Elexon and are not locally agreed with the UMSO by the customer.

Once an EAC calculation has taken place, an EAC Certificate is provided to the customer's appointed electricity supplier for billing, with an electronic copy of the EAC being sent to the appointed data collector. The DNO make a Distribution Use of System charge on the electricity supplier for the delivery of the electricity to the customer's unmetered equipment.

Standard Settlement Configuration (SSC)

Each non-half-hourly supply has a four digit code called the Standard Settlement Configuration (SSC), which specifies the number of registers a meter has, and the times that each register is recording electricity usage. The times that a register is recording is specified with a five digit code Time Pattern Regime (TPR). So for example a supply with SSC 0943 has two registers with TPRs 00404 and 00405. The 00404 TPR register records from 01:00 to 02:30 and 08:00 to 23:30, and the 00405 register records for the rest of the time.{{cite web|last=Elexon |authorlink= |title=What are Standard Settlement Configurations? |date=2011-12-12 |url=https://www.elexonportal.co.uk/faq/view/429 |accessdate=2016-07-05 }}

Meter Point Administration System

Each DNO operates a Meter Point Administration System (MPAS) which holds the following information for each MPAN:

MPRS is the name of the software package that implements the MPAS system for all DNOs.{{cite web | title=Metering Point Registration System | author=St. Clements Services Ltd | url=http://www.st-clements.co.uk/MPRS.html| accessdate=2008-05-29}} Since MPRS is used by most DNOs it is often used interchangeably with the term MPAS.

ECOES

ECOES (formally the Electricity Central Online Enquiry Service) is now the Electricity Enquiry Service (EES) is a website that allows users and authorised industry parties to search for supply details (past and present) using such things as the 13-digit MPAN bottom line number, the meter serial number or the postcode. The user can determine a wide range of data relating to the supply including the full address, meter details, the current energisation status and also the appointed parties (i.e. the supplier, distributor, MOP, DC and DA). The site is populated from information sent from the supplier regarding the metering system.{{cite web | title=Access to ECOES Data | author=MRASCO | url=http://www.mrasco.com/index.php?option=com_content&view=article&id=29&Itemid=29 | accessdate=2009-07-11}}

Only non-domestic users (with two valid MPANs that are not Profile Class 1 or 2) can register to access this service.{{cite web|title=Briefing_Note_on_Customer_Access_NDC_2|url=https://www.ecoes.co.uk/documents/user_guides/Briefing_Note_on_Customer_Access_NDC_2.pdf|website=ECOES|publisher=MRASCO|accessdate=25 June 2015}}

Check digit modulus

= Check digit =

The final digit in the MPAN is the check digit, and validates the previous 12 (the core) using a modulus 11 test. The check digit is calculated thus:

  1. Multiply the first digit by 3
  2. Multiply the second digit by the next prime number (5)
  3. Repeat this for each digit (missing 11 out on the list of prime numbers for the purposes of this algorithm)
  4. Add up all these products
  5. The check digit is the sum modulo 11 modulo 10.{{cite web |url=http://www.energy-retail.org.uk/pdfs/Data%20Item%20Definition%20v1%20final.pdf |title=Data Item Definition v1 final |author=Energy Retail Association |page=23 |url-status=dead |archiveurl=https://web.archive.org/web/20070925074454/http://www.energy-retail.org.uk/pdfs/Data%20Item%20Definition%20v1%20final.pdf |archivedate=2007-09-25 |accessdate=2014-02-25}}

class="wikitable collapsible autocollapse"
MPAN verification examples
The algorithm in Java is:

int checkDigit(String toCheck) {

int[] primes = {3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43};

int sum = 0;

for (int i = 0; i < primes.length; i++) {

sum += Character.getNumericValue(toCheck.charAt(i)) * primes[i];

}

return sum % 11 % 10;

}

In Matlab:

function check = checkdigits(MPANCore)

% MPANCore is a cell array of 13 digit strings.

% Check is a boolean vector the same size as MPANCore.

% (100,000 MPANs in 0.05 seconds.)

core = double(char(MPANCore)')-48; c = core(1:12,:);

p = [3 5 7 13 17 19 23 29 31 37 41 43]' * ones(1, size(c, 2));

m = mod(mod(sum(p.*c), 11), 10); k = core(13,:); check = m == k;

In Pascal / Delphi:

function CheckDigit(MPANCore : array of Byte): Integer;

const

Primes : array [0..11] of Byte = (3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43);

var

i : integer;

begin

Result := 0;

for i := 0 to 11 do

Result := Result + (MPANCore[i] * Primes[i]);

Result := Result mod 11 mod 10;

end;

In Ruby:

  1. where mpan is a string

def check_digit(mpan)

primes = [3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43]

(0..11).inject(0) { |sum, n| sum + (mpan[n, 1].to_i * primes[n]) } % 11 % 10

end

In Visual Basic:

Public Function mpancheck(mpan As String) As Boolean

' Michael Diarmid (EDF)

' Updated 04/08/2010 MD

' Returns True / False if MPAN is valid

On Error GoTo inval

Dim c As Variant, sum As Integer, i as Byte

c = Array(0, 3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43)

For i = 1 To 12

sum = sum + (Mid(mpan, i, 1) * c(i))

Next i

If Right(mpan, 1) = ((sum Mod 11) Mod 10) Then

mpancheck = True

Else

inval:

mpancheck = False

End If

End Function

In VisualBasic.Net 2010:

Public Function mpancheck(mpan As String) As Boolean

' Michael Diarmid (EDF)

' Updated 04/08/2010 MD

' Returns True / False if MPAN is valid

' Revised by Tym Huckin (16/03/2012) for VB 2010

On Error GoTo inval

Dim c As Object, sum As Integer

c = New List(Of Integer) From {0, 3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43}

For i = 1 To 12

sum = sum + (Mid(mpan, i, 1) * c(i))

Next i

If sRight(mpan, 1) = ((sum Mod 11) Mod 10) Then

Return True

Else

inval:

Return False

End If

End Function

Public Function sRight(sSTRING As String, iLEN As Integer) As String

Dim sRET As String = ""

Try

If iLEN >= Len(sSTRING) Then

sRET = sSTRING

End If

sRET = Mid(sSTRING, Len(sSTRING) - (iLEN - 1), iLEN)

Catch ex As Exception

sRET = ""

End Try

Return sRET

End Function

Or VB.Net 2010, avoiding the use of VB6 Compatibility Library :

'''

''' Validates an MPAN number

'''

''' At least the last 13 digits from the MPAN number, including the check digit,

''' expressed as a string

''' True for valid, otherwise false

''' Written by Martin Milan, May 2012, avoiding use of VB6 compatibility library, for .Net 4.0 Client Profile

Public Function MPANIsValid(mpan As String) As Boolean

' Set initial conditions.

Dim validationResult As Boolean = False

If mpan.Length > 12 Then

'Read the check digit into an Integer variable.

Dim intCheckDigit As Integer

If Integer.TryParse(mpan.Substring(mpan.Length - 1), intCheckDigit) Then

Dim strTest As String = mpan.Substring(mpan.Length-13,12)

Dim intPrimes() As Integer = { 3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43}

Dim productTotal As Integer = 0

Dim blnError As Boolean = False

For i As Integer = 0 To 11 Step 1

Dim intTestDigit As Integer

If Integer.TryParse(mpan.Substring(i,1), intTestDigit) Then

productTotal += (intTestDigit * intPrimes(i))

Else

blnError = True

Exit For

End If

Next

If Not blnError Then

validationResult = ((productTotal Mod 11 Mod 10) = intCheckDigit)

Else

validationResult = False ' Due to a parsing error.

End If

End If

End If

Return validationResult

End Function

In C#:

///

/// Validates an MPAN number.

///

/// At least the last 13 digits from the MPAN number, including the check digit,

/// expressed as a string.

/// True for valid, otherwise false.

public static bool MpanIsValid(string mpan)

{

// Set initial conditions.

bool validationResult = false;

if (mpan.Length > 12)

{

// Read the check digit into an Integer variable.

int intCheckDigit = 0;

if (int.TryParse(mpan.Substring(mpan.Length - 1), out intCheckDigit))

{

string strTest = mpan.Substring(mpan.Length - 13, 12);

int[] intPrimes = {3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43};

int productTotal = 0;

bool blnError = false;

for (int i = 0; i <= 11; i++)

{

int intTestDigit = 0;

if (int.TryParse(strTest.Substring(i, 1), out intTestDigit))

{

productTotal += (intTestDigit * intPrimes[i]);

}

else

{

blnError = true;

break;

}

}

if (!blnError)

{

validationResult = ((productTotal % 11 % 10) == intCheckDigit);

}

else

{

validationResult = false; // Due to a parsing error.

}

}

}

return validationResult;

}

As a formula in Excel 365:

'MPAN in Cell A1

=IF(RIGHT(MOD(SUM(MID(A1,SEQUENCE(12),1)*{3;5;7;13;17;19;23;29;31;37;41;43}),11))=RIGHT(A1),"Correct","Invalid MPAN")

In Python:

def check_digit(mpan):

"""Check MPAN digit.

Args:

mpan -- The first 12 digits of the MPAN number, excluding the check digit.

"""

return sum(prime * int(digit) for prime, digit in \

zip([3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43], mpan)) % 11 % 10

In PL/SQL:

create or replace function mpan_check(mpan in varchar2) return boolean is

--CDP ATKINSON

res integer := 0;

TYPE prime_tab IS VARRAY(12) OF integer;

primes prime_tab := prime_tab (3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43);

begin

for i in 1..12 loop

res := res + to_number( substr( mpan, i, 1) ) * primes (i);

end loop;

return to_char(mod(mod(res , 11) , 10)) = substr(mpan,13,1);

end mpan_check;

In JavaScript:

function checkMPAN(mpan) {

var primes = [3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43];

var sum = 0;

var m = mpan.toString();

if (m.length - 1 === primes.length) {

for (var i = 0; i < primes.length; i++) {

sum += parseInt(m.charAt(i)) * primes[i];

}

return sum % 11 % 10 === parseInt(m.charAt(12));

}

return false;

}

In PHP:

function checkMPAN($mpan)

{

$primes = array(3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43);

$sum = 0;

$mpan = str_split($mpan);

if ((count($mpan) - 1) == count($primes)) {

for ($i = 0; $i < count($primes); $i++) {

$sum += $mpan[$i] * $primes[$i];

}

return (($sum % 11 % 10) == end($mpan)) ? true : false;

} else {

return false;

}

}

In SQL Server:

CREATE FUNCTION is_valid_mpan

( @mpan VARCHAR(50) )

RETURNS INT

AS

BEGIN

--Tim Foster (2013-01-04)

DECLARE @is_mpan INT

,@x INT = 1

,@sum INT = 0

DECLARE @arr TABLE (id INT IDENTITY(1, 1), val INT)

INSERT INTO @arr(val) VALUES(3),(5),(7),(13),(17),(19),(23),(29),(31),(37),(41),(43)

WHILE @x <= 12

BEGIN

SELECT @sum = @sum + (SUBSTRING(@mpan, @x, 1) * val)

FROM @arr

WHERE id = @x

SELECT @x = @x + 1

END

IF RIGHT(@mpan, 1) = ((@sum % 11) % 10)

BEGIN

SELECT @is_mpan = 1

END

ELSE

BEGIN

SELECT @is_mpan = 0

END

RETURN @is_mpan

END

In MySQL:

CREATE DEFINER=`root`@`%` FUNCTION `is_valid_mpan`(mpan varchar(13)) RETURNS int(11)

begin

DECLARE is_mpan INT;

DECLARE x INT;

DECLARE sum INT;

declare ret int;

set x = 1;

set sum = 0;

CREATE TEMPORARY TABLE IF NOT EXISTS arr

SELECT 1 `id`, 3 `val` union all

SELECT 2 `id`, 5 `val` union all

SELECT 3 `id`, 7 `val` union all

SELECT 4 `id`, 13 `val` union all

SELECT 5 `id`, 17 `val` union all

SELECT 6 `id`, 19 `val` union all

SELECT 7 `id`, 23 `val` union all

SELECT 8 `id`, 29 `val` union all

SELECT 9 `id`, 31 `val` union all

SELECT 10 `id`, 37 `val` union all

SELECT 11 `id`, 41 `val` union all

SELECT 12 `id`, 43 `val`;

WHILE x <= 12 DO

SELECT (SUBSTRING(mpan, x, 1) * val)

into ret

FROM arr

WHERE id = x;

set sum = sum + ret;

set x = x + 1;

END while;

IF RIGHT(mpan, 1) = ((sum % 11) % 10) then

set is_mpan = 1;

ELSE

set is_mpan = 0;

end if;

drop TEMPORARY table arr;

RETURN is_mpan;

end;

In Swift 3 is:

func isValid(mpan: String) -> Bool {

let primes = [3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43]

let chars = Array(mpan.characters).map({Int(String($0))}).flatMap({$0})

return zip(primes, chars).reduce(0) { $0 + $1.0 * $1.1} % 11 % 10 == chars.last!

}

In Apex (Salesforce):

/**

* @description Validates an MPAN. Written by Adam Dry June 2018. Apex version 43

* @param mpan the 13 digit MPAN including the check digit on the end

*/

public Boolean mpanIsValid(String mpan) {

List primes = new List{3, 5, 7, 13, 17, 19, 23, 29, 31, 37, 41, 43};

// Read the check digit into an Integer variable

Integer checkDigit = Integer.valueOf(mpan.right(1));

String strTest = mpan.substring(0, 12);

Integer productTotal = 0;

for (Integer i = 0; i <= 11; i++) {

Integer testDigit = Integer.valueOf(strTest.Substring(i, i + 1));

productTotal += (testDigit * primes[i]);

}

Integer computedCheck = Math.mod(Math.mod(productTotal, 11), 10);

Boolean validationResult = (computedCheck == checkDigit);

return validationResult;

}

See also

References

{{Reflist|2}}

{{Energy in the United Kingdom|sources}}

Category:Electric power in the United Kingdom

Category:Electricity meters