endofyear

This page explains how to use the endofyear function in APL.

Use the endofyear function in APL to return the end of the year containing a given datetime value. The function returns a datetime representing the last moment of that year (December 31, 23:59:59.9999999).

You can use endofyear to align events to year-end boundaries, which is useful for annual aggregation, fiscal year analysis, and year-over-year comparisons in dashboards.

Use it when you want to:

  • Group events by year-end boundaries for annual reporting.
  • Compare activity or metrics across calendar years.
  • Align timestamps to the end of the year for time-series bucketing.

Usage

Syntax

endofyear(datetime [, offset])

Parameters

NameTypeDescription
datetimedatetimeThe input datetime value.
offsetlongOptional: The number of years to offset from the input datetime. Default is 0.

Returns

A datetime representing the end of the year for the given date, shifted by the offset if specified. The return value is December 31 at 23:59:59.9999999 of the input year.

Use case examples

Count total HTTP requests per year to understand annual traffic volume.

Query

['sample-http-logs']
| extend year_end = endofyear(_time)
| summarize total_requests = count() by year_end
| sort by year_end asc

Run in Playground

Output

year_endtotal_requests
2024-12-31T23:59:59.9999999Z1523
2025-12-31T23:59:59.9999999Z2841

This query groups each HTTP log entry by its year-end boundary and counts the total number of requests per year.

Track yearly trace volume by service to compare annual activity across services.

Query

['otel-demo-traces']
| extend year_end = endofyear(_time)
| summarize trace_count = count() by year_end, ['service.name']
| sort by year_end asc

Run in Playground

Output

year_endservice.nametrace_count
2024-12-31T23:59:59.9999999Zfrontend5320
2024-12-31T23:59:59.9999999Zcart2150
2025-12-31T23:59:59.9999999Zfrontend6100

This query counts traces per service per year, using year-end boundaries for grouping.

Summarize yearly error totals to identify years with elevated server error rates.

Query

['sample-http-logs']
| where toint(status) >= 500
| extend year_end = endofyear(_time)
| summarize error_count = count() by year_end
| sort by year_end asc

Run in Playground

Output

year_enderror_count
2024-12-31T23:59:59.9999999Z187
2025-12-31T23:59:59.9999999Z342

This query filters for server errors and groups them by year-end boundary to reveal annual error totals.

  • startofyear: Returns the start of the year for a datetime value.
  • endofmonth: Returns the end of the month for a datetime, useful for monthly boundary calculations.
  • endofweek: Returns the end of the week for a datetime value.
  • endofday: Returns the end of the day for a datetime value.
  • getyear: Extracts the year part from a datetime as an integer.

Other query languages