13.5Text functions
A code to cut up, a name to put in capitals, your texts often need a helping hand. These functions work on text, like their Excel counterparts. The examples start from the product code A101.
13.5.1LEFT, RIGHT and MID
In Excel
| DAX | LEFT | RIGHT | MID |
|---|---|---|---|
| Excel | LEFT | RIGHT | MID |
| Match |
The product code hides the brand. Its second character is 1 for Velmo and 2 for Kordan. If your extract gave you only the code, you would find the brand by taking this character.
LEFT, RIGHT and MID take part of a text, at the start, at the end or in the middle.
| The start | LEFT( <text>, [<number of characters>] ) |
|---|---|
| The end | RIGHT( <text>, [<number of characters>] ) |
| The middle | MID( <text>, <start position>, <number of characters> ) |
All three first expect the text, often a column. LEFT and RIGHT then expect the number of characters to keep. If it is left out, they keep just one. MID expects the start position, then the number of characters.
On row A101:
- LEFT( Products[Product Code], 1 ) returns A.
- RIGHT( Products[Product Code], 3 ) returns 101.
- MID( Products[Product Code], 2, 1 ) returns 1.
MID starts at the 2nd character and takes one.
| [Code] | [LEFT] | [RIGHT] | [MID] | |
|---|---|---|---|---|
| 1 | A101 | A | 101 | 1 |
| 2 | A102 | A | 102 | 1 |
| 3 | A201 | A | 201 | 2 |
| 4 | A202 | A | 202 | 2 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
RIGHT returns the text “101,” not the number 101. VALUE( RIGHT( Products[Product Code], 3 ) ) turns it into a number.
Practice
Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.
Direct useCalculated columnDifficulty
In a library, the call number of each book starts with the three letters of its section. Add to the “Books” table the calculated column “Section,” which keeps the first three characters of the call number.
Books Title Call Number Dune ROM-0451 Roman Empire HIS-0112 The Cosmos SCI-0890 Which formula should you write for “Section”?
Combined useCalculated columnDifficulty
The library wants to spot its novels, filed in the “ROM” section. Add to the “Books” table the calculated column “Novel,” which shows “Yes” or “No.”
Books Title Call Number Dune ROM-0451 Roman Empire HIS-0112 The Cosmos SCI-0890 Direct useCalculated columnDifficulty
A hotel gives each booking a code that ends with a 4-digit number. Add to the “Bookings” table the calculated column “Number,” which keeps the last four characters of the code.
Bookings Guest Code Durand R2026-0147 Martin R2026-0152 Combined useCalculated columnDifficulty
The hotel wants to sort the bookings by number, as numbers. The number is made of the last four characters of the code. Add to the “Bookings” table the calculated column “Number,” as a number.
Bookings Guest Code Durand R2026-0147 Martin R2026-0152 Direct useCalculated columnDifficulty
A sports club gives each member a number whose 5th character shows the category, “J” for junior, “A” for adult, “S” for senior. Add to the “Members” table the calculated column “Category,” which keeps this single character.
Members Name Number Inès 2026J0458 Hugo 2025A0112 Jade 2026S0031 Combined useCalculated columnDifficulty
The club offers a reduced rate to juniors. In each member’s number, the 5th character shows the category, “J” for junior. Add to the “Members” table the calculated column “Rate,” which shows “Reduced” or “Full.”
Members Name Number Inès 2026J0458 Hugo 2025A0112 Jade 2026S0031
The rest of this lesson is part of izyDAX Pro
You have just read the first section. The next 3, their animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.