Data type conversion
Whether you import or create data yourself, setting the correct data type is essential. Sometimes, you’ll need to change a data type temporarily to make things work—like making sure a piece of data is accepted by a certain function, or when you’re mixing different types of data.
Let’s say you have a number that’s been input as text. To do any math with it, you’ll need to change it from text to a numeric format. Or, if you’re trying to add a date to a text message, you’ll need to switch the date to a text format first. This kind of switching is often needed when your data is stored in tables.
For these situations, the M language has two main ways to convert your values to another type. You could:
- Create a new column and use a conversion function within an expression
- Transform entire columns to another type
We will look at both approaches in the following sections.