DATE_BUCKET() function in Fabric Data Warehouse (Generally Available)
Microsoft Fabric Data Warehouse provides an expressive SQL language that empowers users to easily create a wide range of reports and analytics solutions. With its rich set of built-in functions and intuitive syntax, Fabric Data Warehouse enables data professionals to efficiently transform, aggregate, and analyze data for diverse business needs.
We have introduced a new DATE_BUCKET() function in Fabric Data Warehouse SQL language that makes reporting and analytics even easier.
In this blog post, you’ll discover how it simplifies time-based reporting and makes grouping dates effortless.
Time-based reporting and analysis
One of the most common tasks in analytics is aggregating time-based data by years, quarters, or months. The T-SQL language provides a variety of functions such as DATEPART(), YEAR(), MONTH(), or WEEK() that enable you to extract specific parts of a date and aggregate your data accordingly. For example, if you want to display a quarterly distribution of sales orders, you can use a query like this:
SELECT
DATEPART(QUARTER, OrderDate) AS [Quarter],
COUNT(*) AS [Number of orders]
FROM SalesOrders
GROUP BY DATEPART(QUARTER, OrderDate)
ORDER BY DATEPART(QUARTER, OrderDate)
However, challenges arise when you need to build reports on custom time ranges, such as 2-month periods, 3-week periods, or 5-minute intervals where there are no direct built-in functions to match these specific groupings. This is where specialized functions like DATE_BUCKET() become invaluable, simplifying the process of creating flexible, custom time-based aggregations.
The DATE_BUCKET() function bucketizes the date argument into equidistant buckets of the specified width and returns the first date in that bucket. The syntax of this function is:
DATE_BUCKET(unit, length, datetime)
This function returns the first datetime in the period of the given length and unit. For the unit and length parameters, you can specify values such as 3 WEEK, 5 MINUTE, 2 MONTH, or any other integral length.
The DATE_BUCKET() function will position the provided datetime within one of these buckets and return the starting date of that bucket, making it easy to aggregate data over custom time intervals.
For example, the following query uses the DATE_BUCKET() function to return the distribution of sales orders in 2-month periods instead of quarters:

You can easily change the date periods in the report just by changing bucket size to some other value.
For example, the following report will group the date values in 3-week periods:

You can easily change the interval length and use any bucket size that fits your needs in the reports, making your queries highly adaptable to various time-based analysis scenarios. Whether you need to group data by days, weeks, months, or even custom periods, DATE_BUCKET offers the versatility required for modern reporting tasks.
Conclusion
DATE_BUCKET is a small addition to the T-SQL language in Fabric Data Warehouse that you need to be aware of because it might be incredibly useful for building flexible, date-based reports. By allowing you to define custom time intervals, it streamlines complex aggregations and enhances your ability to analyze trends over any period.
Learn more about this function in the Fabric Data Warehouse documentation.