Mitchell Pearson, a trainer at Pragmatic Works, dives into a practical Power Query tutorial focused on working with date data. In this video, he explains how to handle date conversion errors and demonstrates how to calculate age from a date of birth directly in Power Query, emphasizing best practices for efficient data modeling.
Mitchell begins the tutorial by addressing a common issue: converting text-based date fields into proper date formats. He demonstrates a typical error where attempting to convert a text column directly to a date fails. Key steps to resolve this include:
This two-step approach prevents parsing errors commonly encountered when working with CSV or Excel data imports in Power Query.
Mitchell emphasizes that date transformations should be performed in Power Query rather than DAX (Data Analysis Expressions). Benefits of handling date conversions in Power Query include:
Next, Mitchell explains how to calculate a customer’s age using Power Query’s UI, without writing any code:
The result is an age calculation based on the difference between the current date and the date of birth.
After generating the age column, Mitchell demonstrates how to refine the calculation to avoid decimal results:
Mitchell also highlights how Power Query simplifies this process with an M code expression that divides the age in days by 365. He mentions the ability to adjust this calculation slightly to account for leap years by changing the divisor to 365.25.
Mitchell further explores additional numeric transformations available in Power Query, including:
These transformations offer a range of capabilities for preparing data before building reports.
Mitchell concludes by emphasizing the importance of performing date conversions and age calculations within Power Query, rather than DAX, to optimize data models. Key points covered in the video include:
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on Power BI and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.