← All challenges

P2 · Power Query · about 10 min

Dates Stored as Text

easy

A partner league sends its game dates as text in day/month/year order: 07/04/2024 is 7 April. After a quick Change Type, the 7 April game shows up on 4 July, and games played after the 12th of a month have no date at all.

Your task

Load Games_text_dates.csv from the SourceFolder folder as a table named Games with columns GameID, Date, Season and TeamID. Date must be a real date (data type Date) with the right day and month for every game.

What the grader checks

You see the situations, not the expected numbers. The expected values are computed live from your file and the source data.

  • T1Every game on its real date
    Games compared row by row with the source file, matched on GameID: 07/04/2024 must be 7 April 2024.
  • C1Date is a date, not text
    Games[Date] has data type Date.

Stuck?

Open one hint at a time.

Hint 1

Which day is 07/04/2024? It depends on who is reading. Which reading does Change Type use?

Hint 2

Change Type reads text with the file's locale. A US locale reads month first. There is a version of Change Type that lets you say which locale the text was written in.

Hint 3 (near-answer)

Right-click the Date column > Change Type > Using Locale..., Data Type Date, Locale English (United Kingdom).

Show the editorial

Solve it first if you can: the editorial gives the answer away.

The trap

Text dates have no built-in order: 07/04/2024 is 7 April in most of the world and July 4 in the US. A plain Change Type reads the text with the file's locale, here English (United States), so every day of 12 or less is silently swapped with the month and every day above 12 fails to convert and loads as a blank. Nothing errors loudly: the games just move.

The fix

Change the type of Date with a locale that writes day first: Change Type > Using Locale > Date, English (United Kingdom).

Why it works

Using Locale tells Power Query how the text was written, separately from the file's own regional setting, so 07/04/2024 is read as day 7, month 4. The column becomes a real date, which sorts, filters and relates correctly to a date table.

When text becomes a date, say which locale wrote it. Never trust a default for day and month order.