Extracting Dates from Irregular Strings in Power Query

PL-300 By islever Editorial Last updated

Short answer

D Use Create Column from Examples to let Power Query intelligently parse the 'YYYY-MM-DD at HH:MM' string into a native Date type suitable for hierarchies.

Question

You have a CSV file that contains user complaints. The file contains a column named Logged. Logged contains the date and time each complaint occurred. The data in Logged is in the following format: 2018-12-31 at 08:59.
You need to be able to analyze the complaints by the logged date and use a built-in date hierarchy.
What should you do?
  1. Add a conditional column that outputs 2018 if the Logged column starts with 2018 and set the data type of the new column to Whole Number.
  2. Split the Logged column by using “at” as the delimiter.
  3. Apply a transformation to extract the last 11 characters of the Logged column and set the data type of the new column to Date.
  4. Create a column by example that starts with 2018-12-31. Correct Answer

Key Takeaways

The trap is trying manual text manipulation; the key insight is that Power Query's AI-driven examples can parse and type-cast complex strings in one step.

Learn how to handle irregular date formats like '2018-12-31 at 08:59' using Create Column from Examples to ensure compatibility with Power BI date hierarchies.

Common mistake: Splitting by delimiter (B) often leaves whitespace or partial data that requires additional manual cleaning and type casting steps, making it less efficient than examples.

Expert Analysis

The Logged column contains a non-standard date format: '2018-12-31 at 08:59'. To use the built-in date hierarchy in Power BI, the column must be of Date or DateTime data type. The goal is to extract just the date portion (YYYY-MM-DD) and convert it.

Option C suggests extracting the last 11 characters ('12-31 at 08:59' is 14 chars, so this logic is flawed if applied blindly, but let's look closer). Actually, '2018-12-31' is 10 characters. The string is '2018-12-31 at 08:59'. Extracting the first 10 characters would give '2018-12-31'. Option C says 'last 11 characters', which would result in '-31 at 08:59' or similar, which cannot be parsed as a standard date easily without complex cleaning. Wait, let's re-read carefully. The format is 'YYYY-MM-DD at HH:MM'. Length is 19. Last 11 chars: 't 08:59'? No. 'at 08:59' is 8 chars. ' at 08:59' is 9. '31 at 08:59' is 12. This option seems technically incorrect for extraction.

Let's look at Option D: Create a column by example. Power Query's 'Column from Examples' feature is intelligent. If you provide an input like '2018-12-31 at 08:59' and want the output '2018-12-31', Power Query will automatically detect that you want to split on ' at ' and take the left part, then set the data type to Date. It handles the formatting and type conversion implicitly. This is the most robust and user-friendly method for irregular formats.

Option A creates a conditional column for years only, losing the month and day, so no date hierarchy. Option B splits by 'at', leaving spaces and potentially time parts, requiring further steps to clean and cast.

Therefore, creating a column by example (D) is the best practice because it allows Power Query to infer the pattern and perform the necessary parsing and typing automatically, ensuring the result is a valid Date type compatible with hierarchies.

Exam Strategy

When dealing with messy data types, prioritize 'From Examples' features first. They reduce error-prone manual coding. Always verify the final column type matches the requirement (Date vs Text) before building hierarchies.

Frequently Asked Questions

Why not just change the data type directly?

Power Query might fail to parse '2018-12-31 at 08:59' directly to Date due to the extra text. You need to clean it first.

Does Column from Examples always work?

It works well for consistent patterns. If the format varies wildly row-to-row, manual M code or splits are safer.

Community Votes

D
100%

100% of anonymous learners picked answer D. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 1 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 1

  1. ds_6852 👍 1 Answered D
    Using "at" as a delimiter leaves spaces in the split columns. D would be a better way to ensure the outcome column is a date.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Practice All PL-300 Questions

Access 116 questions with complete answers and detailed explanations.

View Full PL-300 Practice Test →

← Back to PL-300 Study Guide