MID function in Power BI

How To Use the MID Function in Power BI

What Is MID?

MID is a DAX function within Power BI that allows you to return a string of characters from the middle of a text string using the starting position and length specified.

MID is very similar to the LEFT and RIGHT DAX functions.

Syntax

The syntax for the MID function is below.

=MID(<text>, <start_num>, <num_chars>) 

Parameters

TermDefinition
textThe text string from which you want to extract the characters, or a column that contains text.
start_numThe position of the first character you want to extract. Positions start at 1.
num_charsThe number of characters to return.

Using the MID Function in Power BI

We know what the MID function in power bi does, the syntax for the function, and what the parameters need, but how do we use this DAX function? Let’s find out!

I have a simple dataset that consists of the following columns: ‘Month’, ‘Region’ and ‘Revenue’.

table in Power BI
  1. In your dataset, create a new column.
  2. Following the MID syntax outlined above, enter your own MID calculation on a column of your choice. For this article, I will be using the ‘Region’ column.
  3. I have used the below calculation to get the first 2 characters after the second character in the text string.
  4. Middle 2 = MID(‘RLS Data'[Region], 2, 2)
  5. This calculation takes the ‘Region’ string which contains multiple regions that are represented as text, finds the second character in the string, then takes 2 characters from the second character.
  6. The above calculation will then create a column with the below text in.
MID function in Power BI

Notice how the newly created column contains the middle 2 characters of the region strings? ‘East’ becomes ‘as’ and ‘West’ becomes ‘es’.

Finishing Off

The MID function is an extremely powerful and useful DAX function. It provides functionality to extract a specified number of characters within the given string.

Why not challenge yourself and expand on this article? You know how to use the MID function now, but why not challenge yourself and see what you’re able to do with it? Why not take 5 characters after the first space in a string?

To learn more, please visit Learn DAX

Similar Posts