302 Practical PowerPivot & DAX Formulas for Excel 2010
T
his chapter deals with text (or string) manipulation. Most of the text functions
are the same as their Excel function equivalents; however, they accept text
or column parameters rather than worksheet cells or ranges. Many of these
text functions return text, and as such are usually more suitable for creating calculated
columns in PowerPivot tables rather than measures—text values can’t be added together
to give subtotals and totals in a pivot table (unless you do a COUNT()). Having said
that, if the text value can be converted into a number (for example the string “123”),
then it may be used as an additive measure. Usually, PowerPivot will implicitly do the
conversion, but you can always do it explicitly with the VALUE() function. Please note
that the FORMAT() text function also operates against numbers as well as against text.
C
Key concepts Comparing and finding strings, concatenating and parsing strings,
changing and formatting strings
C
Keywords CONCATENATE(), EXACT(), FIND(), FIXED(), FORMAT(),
LEFT(), LEN(), LOWER(), MID(), REPLACE(), REPT(), RIGHT(), SEARCH(),
SUBSTITUTE(), TRIM(), UPPER(), VALUE()
CONCATENATE() 1/2
Often, your source data is heavily normalized and names and addresses are parsed into
separate columns. This does not always make for easy viewing in a pivot table. Maybe
you want to put columns back together again. You can use the CONCATENATE() function
to reassemble text columns (it also works against numeric columns or a mix of text
and numeric). Slicing or filtering is probably easier if you have the full name of each
employee, rather than only the surname (you might have two or more employees sharing
a surname). The examples are calculated columns on the Northwind Employees table.
Syntax
=CONCATENATE('Employees'[LastName],'Employees'[FirstName])
=CONCATENATE('Employees'[LastName],", ",'Employees'[FirstName])
=CONCATENATE('Employees'[LastName],
CONCATENATE(", ",'Employees'[FirstName]))
='Employees'[LastName] & ", " & 'Employees'[FirstName]