304 Practical PowerPivot & DAX Formulas for Excel 2010
Result
Analysis
The first formula works—only if there’s no region, it looks a little strange (for example,
UK-). Unlike SQL Server (unless the CONCAT_NULL_YIELDS_NULL database option
is set to OFF), PowerPivot treats nulls as blanks, so adding a null region to a country
does not return null. The second formula produces a more pleasing result and is the
one shown in the preceding illustration. If the region is blank (probably because it’s
originally a null value in the source data), then the hyphen (-) is not appended to the
country. The second example has a nested CONCATENATE(). The position of the
nested CONCATENATE() is different from that in the previous set of examples, where it
appears immediately after the outer CONCATENATE(). Both varieties work.
The second example here is a lengthy formula. As such, part of it may scroll out of
view as you edit. There are two tricks that are quite handy in these situations. One,
you can increase the height of the formula bar (for calculated columns) or the Formula
text box (for measures) by dragging. Two, you can force your formula to word-wrap by
pressing alt-enter.
EXACT()
EXACT() compares two text values and returns either TRUE or FALSE. The first
formula is an example. The second example shows an alternative approach (using
an equality test) that produces the same result. More useful is the third formula, or
its equivalent in the fourth formula. The examples are calculated columns in the
Northwind Orders table.
Syntax
=EXACT('Orders'[CustomerID],"QUICK")
=IF('Orders'[CustomerID] = "QUICK", TRUE(), FALSE())
=IF(EXACT('Orders'[CustomerID],"QUICK"), "QUICK-Stop", "Others")
=IF('Orders'[CustomerID] = "QUICK", "QUICK-Stop", "Others")