Date.DaysInMonth

Date

Returns the number of days in the month of the given date.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Date.DaysInMonth(dateTime as any) as nullable number

Parameters

NameTypeRequiredDescription
dateTimeanyYesA date, datetime, or datetimezone value.

Return Value

numberThe number of days in the month (28, 29, 30, or 31).

Remarks

Date.DaysInMonth returns the number of days in the month containing the given date, datetime, or datetimezone value. Possible return values are 28, 29, 30, or 31. February returns 28 in common years and 29 in leap years. This is useful for computing month-end dates, prorating amounts, or building dynamic date calendars. If the input is null, the function returns null.

A common use case is computing what fraction of a month an event covers (e.g., for proration). You can divide the number of active days by Date.DaysInMonth to get the fractional month weight. Another use case is constructing the last day of a month: #date(Date.Year(d), Date.Month(d), Date.DaysInMonth(d)), though Date.EndOfMonth is more concise for that purpose.

Note that Date.DaysInMonth requires any date within the target month — it does not matter if you pass the 1st, 15th, or last day; the result is the same for all dates in that month.

Examples

Example 1: Count days in each order month

Table.AddColumn(
    Table.SelectColumns(
        Table.FirstN(Sales, 5),
        {"OrderID", "OrderDate"}
    ),
    "DaysInMonth", each Date.DaysInMonth([OrderDate]), Int64.Type
)
Result
OrderID
OrderDate
DaysInMonth
111/15/202431
221/18/202431
332/1/202429
442/10/202429
553/5/202431

Example 2: Days in February for a leap year vs. common year

#table(
    type table [Year = number, Date = date, DaysInFeb = number],
    {
        {2024, #date(2024, 2, 1), Date.DaysInMonth(#date(2024, 2, 1))},
        {2023, #date(2023, 2, 1), Date.DaysInMonth(#date(2023, 2, 1))}
    }
)
Result
Year
Date
DaysInFeb
12,0242/1/202429
22,0232/1/202328

Example 3: Prorate a monthly amount by days active

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(Sales, 5), {"OrderID", "OrderDate", "UnitPrice"}),
    "ProratedPrice",
    each
        let
            daysInMonth = Date.DaysInMonth([OrderDate]),
            dayOfMonth = Date.Day([OrderDate]),
            remainingDays = daysInMonth - dayOfMonth + 1
        in
            Number.Round([UnitPrice] * remainingDays / daysInMonth, 2),
    type number
)
Result
OrderID
OrderDate
UnitPrice
ProratedPrice
111/15/20242513.71
221/18/20245022.58
332/1/20241515
442/10/20247555.17
553/5/20242521.77

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks