Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Date.Day Function: Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Date.Day function in Power Query returns the day of the month as a number from 1 to 31 for a given date value. To use it, you need a date column (or a date value) in your query, then add a custom column or transform an existing one with the formula Date.Day([YourDateColumn]). That's the short answer. The rest of this guide walks through exactly how to apply it in Excel and Power BI, plus the common pitfalls and fixes.

What You'll Need

  • Power Query available in Excel (Data > Get & Transform Data) or Power BI Desktop (Transform Data).
  • A table or data source that contains at least one column with date values (or values that can be converted to dates).
  • Basic familiarity with the Power Query Editor window and the formula bar.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Home > Transform Data to open the Power Query Editor with your existing query. If you're starting from an external source, use Get Data and pick your connector.
  2. Confirm the column is a date type. Select the column that holds your dates. Check the icon in the column header or look at the Data Type dropdown in the Home tab. If it says “Any” or “Text,” click the dropdown and choose Date. This step is critical: Date.Day only works on date values, not on text that looks like a date.
  3. Add a custom column. Go to the Add Column tab and click Custom Column. In the dialog, give the new column a name, for example “Day of Month.” In the formula box, type but replace with the actual name of your date column, including the square brackets. For a column named “OrderDate,” the formula is Date.Day([OrderDate]) . Click OK.
  4. Check the result. A new column appears with numbers 1 through 31. If you see errors, the most likely cause is that the source column isn't a true date type or contains nulls. See Troubleshooting below.
  5. Optional: transform in place instead. If you don't need to keep the original date, you can select the date column, go to the Transform tab, and use Date > Day > Day. This replaces the column values with the day number. Use Add Column > Date > Day if you want to keep the original date and add a new column instead.
  6. Handle nulls if needed. If your date column has blanks, Date.Day returns null for those rows. To avoid errors downstream, you can wrap the formula: if [OrderDate] = null then null else Date.Day([OrderDate]). This keeps the column clean.
  7. Apply and load. Click Close & Load (Excel) or Close & Apply (Power BI) to bring the results back to your worksheet or data model. The new column is now available for filtering, sorting, or building visuals.

Note: Menu labels can differ slightly between Excel versions, Power BI versions, and regional settings. The core steps and the Date.Day function itself are consistent across both platforms.

Common Mistakes

  • Using text instead of date. If the column data type is Text, Date.Day will throw an error. Always convert to Date first. A common symptom is “Expression.Error: We cannot convert the value to type Date.”
  • Forgetting the square brackets. In the Custom Column formula, column references must be in square brackets, e.g., [OrderDate], not OrderDate. Without brackets, Power Query treats it as a function or keyword.
  • Assuming Date.Day returns a text value. It returns a number. If you need “01” instead of “1,” you'll need to format it separately, for example with Number.ToText(Date.Day([OrderDate]), "00").
  • Ignoring locale when converting text to date. If your source dates are text like “31/12/2024” and your locale expects “MM/DD/YYYY,” the conversion may fail or swap day and month. Use the locale option in the change type step or parse with Date.FromText and a culture code.
  • Expecting Date.Day to work on datetime values without conversion. A datetime column (with time) is not the same as a date column. Convert it to Date first, or use Date.Day(DateTime.Date([YourDateTimeColumn])).

Tips

  • Use the Add Column > Date > Day button for a quick, formula-free way to extract the day number. It writes the same Date.Day logic behind the scenes.
  • If you need the day name (Monday, Tuesday, etc.), use Date.DayOfWeekName instead. Date.Day only gives the numeric day of the month.
  • Combine with Date.Month and Date.Year to build a full date key or to group by day across months.
  • For sorting by day of week, use Date.DayOfWeek (returns 0 for Sunday through 6 for Saturday by default) rather than Date.Day, which is day of month.
  • When working with large datasets, add the custom column after filtering out unneeded rows to keep the query fast.

Troubleshooting

If you see errors after adding the column, work through these checks in order:

  • Check the data type of the source column. Select the column and look at the Data Type dropdown. If it's not Date, change it. If the change fails, the column likely contains text that isn't in a recognized date format. Clean or parse the text first.
  • Look for nulls or blanks. Date.Day(null) returns null, which is not an error, but downstream steps may fail if they expect a number. Use the null-handling formula shown in Step 6.
  • Verify the column name. In the Custom Column dialog, the column name must match exactly, including spaces. If your column is “Order Date” with a space, use [Order Date].
  • Check for datetime values. If the column type is Date/Time, convert it to Date first (Transform > Data Type > Date) or wrap with DateTime.Date.
  • If the formula bar shows a different formula than you typed, Power Query may have auto-corrected a name. Click the gear icon next to the step to review and edit.
  • Still stuck? Remove the custom column step and try the built-in Date > Day button instead. If that works, compare the generated formula to yours to spot the difference.

Frequently Asked Questions

What does Date.Day return for a date like 15 March 2024?

It returns 15, the day of the month as a number.

Can I use Date.Day on a column that contains text dates?

No, you must first convert the column to the Date data type. If the text is in a non-standard format, use Date.FromText with the correct culture or fix the source data.

Does Date.Day work in both Excel and Power BI?

Yes, Power Query is the same engine in both, so the function and steps are identical. Menu locations may vary slightly.

How do I get the day of the week instead of the day of the month?

Use Date.DayOfWeek or Date.DayOfWeekName. Date.Day is strictly the numeric day of the month (1–31).

Why do I get an error saying “We cannot convert the value to type Date”?

That means the column contains values that aren't valid dates, or the column's data type is not Date. Check for blanks, text, or mixed formats and clean the column before applying Date.Day.

Can I use Date.Day in a calculated column in the data model instead of Power Query?

Yes, in Power BI you can use DAX DAY() for a similar result, but Power Query's Date.Day is applied during data load and is often more efficient for large models.