Using the LEFT Function
The LEFT
function is very useful when you need to parse a string to get a subset of the data. This is often used to make the data more meaningful for your users. In this recipe, you will create a column on the Manner_of_Crash table to return the first nine letters of each description. Then you will make the LEFT
function use a dynamic argument to determine the number of characters to find a comma. On this table, you can now create a hierarchy that would group the two sideswipe rows into a single group. The LEFT function has a required syntax of LEFT(<text>,<num_chars>)
.
How to do it...
Open the Chapter_9_DAX solution, select the CRASH_DATA_T table, and make sure you are in the data Grid view.
Scroll to the right until you find the Add Column. Then in the expression box, add the formula to return the first nine characters of the field. Then press Enter to create the calculation. You will then see a label added to each row:
=LEFT([Manner_of_Crash])
.On the Properties...