Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin the OneLake & Platform Admin teams for an ask US anything on July 16th. Join now.
When working in Power BI’s Power Query Editor, you often need to assign proper data types to your columns. For example, imagine a product table with columns Product, Sales, Date, and Sales Condition. One of these columns might have the data type Any (indicating it contains both text and numbers). If you use the usual approach clicking the data type icon or using the ribbon to change it to Text. Power BI will add a new Changed Type step to your query. While this works, each additional step can clutter your Applied Steps pane and potentially impact performance in complex queries.
After editing the M code to include the data type, the Power Query Editor applies the change without adding a separate step. In this example, a custom column was added with type text specified (for a text), so there is no additional “Changed Type” step in the Applied Steps pane. Defining the type inline keeps the query steps list streamlined.
By editing the M formula, the column’s type is set within the existing step instead of as a separate step. For instance, if your step was adding a custom column, the formula might look like:
= Table.AddColumn(#"PreviousStep", "NewColumnName", each <logic>, type text)
Power Query’s M language uses specific keywords or type constants for data types. Here are some common ones you can use when editing the formula:
For example, Int64.Type is used for integer columns with no decimals, whereas type number covers decimal or whole numbers . Using the correct type ensures your data is properly recognized in Power BI.
Let’s say you want to add a new True/False flag column. You decide that rows meeting a certain condition should be marked as TRUE. One quick way to do this in Power Query is to output a 1 for true and 0 for false in a custom column formula, since Power BI will interpret 1 as TRUE and 0 as FALSE in a logical context.
However, to make this new column a Boolean logical type, you should explicitly define its type in the formula. If you’re unsure what the M syntax is for a Boolean, try this trick:
Using type logical in the formula ensures the column is boolean without an extra conversion step. This technique can be used whenever you create custom columns that need a specific data type.
By defining data types directly in the M code, you avoid unnecessary steps and keep your queries tidier. As your Power BI queries grow, eliminating extra steps makes them easier to read and maintain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.