Description
The MID
function extracts a specified number of characters from the middle of a text value.
Usage
MID(text, start_num, number_characters)
Argument | Type | Required | Description |
---|---|---|---|
text | Text | Yes | Input text |
start_num | Numeric | Yes | Position of the first character you want to extract in text. The first character in text has start_num 0. |
number_characters | Numeric | Yes | Number of characters to extract |
Remarks
If the text
argument is blank, or the number_of_characters
is zero, then the result is a blank text value.
Examples
The MID
function, like the LEFT
and RIGHT
functions, is useful in extracting information from coding systems.
P-Codes
Administrative divisions are often assigned P-Codes or Place codes to facilitate information sharing. These codes are often hierarchial, with different groups of characters corresponding to different administrative levels. Afghanistan, for example, is divided into 34 provinces, which are then divided into districts. The table below shows examples of P-Codes assigned by OCHA for districts:
P-Code | Province | District |
---|---|---|
AF1801 | Takhar | Taloqan |
AF1802 | Takhar | Hazar Sumuch |
AF1904 | Kunduz | Khan Abad |
AF1905 | Kunduz | Imam Sahib |
You can see from the example above that the third and fourth characters of the P-Code indicate the province: Takhar is 18, and Kunduz province is 19.
You can calculate this code by using the MID([P-Code], 2, 2)
Formula.