Sr. Content Developer at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
160284 stories
·
33 followers

Multiplicative Aggregates with the PRODUCT Function in SQL Server 2025

1 Share

This blog post explores the new PRODUCT function in SQL Server 2025, which calculates the product of a set of numeric values — similar to how SUM and AVG work for addition and averaging, but for multiplication.

Prior to SQL Server 2025, SQL Server lacked a built-in way to compute the product of values in a set. You had to use workarounds like looping or user-defined aggregates. With PRODUCT, this is now a simple one-line expression.

PRODUCT supports both aggregate and analytic (windowed) forms and works with both ALL values (default) and DISTINCT values. Nulls are ignored, and the function is compatible with all numeric types except bit.

Compute Product of Prices for Each Product

The first example illustrates how to use the new PRODUCT aggregate function in SQL Server 2025 to calculate the cumulative product of prices for each product across multiple orders. It also shows how to compute the product considering only distinct price values.

CREATE TABLE OrderDetail (
OrderId int,
ProductId int,
Price decimal(10, 4)
)
INSERT INTO OrderDetail
(OrderId, ProductId, Price) VALUES
(1, 101, 136.87),
(1, 102, 29.57),
(1, 103, 396.85),
(2, 101, 136.87),
(2, 102, 29.57),
(3, 101, 136.87),
(3, 102, 29.57),
(4, 101, 149.22),
(4, 102, 29.57)
-- Compute product of all prices and distinct prices for each ProductId
SELECT
ProductId,
ProductOfPrices = PRODUCT(Price),
ProductOfDistinctPrices = PRODUCT(DISTINCT Price)
FROM
OrderDetail
GROUP BY
ProductId

Result:

ProductIdProductOfPricesProductOfDistinctPrices
101382606053.82916220423.741400
102764548.95334829.570000
103396.850000396.850000

Alternative using OVER (PARTITION BY ...)

This version computes the product for each row using a windowed aggregate (that is, using OVER rather than GROUP BY). This allows you to retain the detail rows (which were lost in the previous GROUP BY query) while also showing the total product per partition.

SELECT
ProductId,
OrderId,
Price,
ProductOfPrices = PRODUCT(Price) OVER (PARTITION BY ProductId)
FROM
OrderDetail
ORDER BY
ProductId,
OrderId

Result:

ProductIdOrderIdPriceProductOfPrices
1011136.8700382606053.829162
1012136.8700382606053.829162
1013136.8700382606053.829162
1014149.2200382606053.829162
102129.5700764548.953348
102229.5700764548.953348
102329.5700764548.953348
102429.5700764548.953348
1031396.8500396.850000

Compounded Return from Periodic Rates

The next example uses PRODUCT to compute the compounded return for financial instruments over multiple time periods.

CREATE TABLE Instrument (
InstrumentId varchar(10),
Period tinyint,
RateOfReturn decimal(10, 4)
)
INSERT INTO Instrument
(InstrumentId, Period, RateOfReturn) VALUES
('BOND1', 1, 0.035),
('BOND1', 2, 0.0275),
('BOND1', 3, 0.0325),
('ETF1', 1, 0.08),
('ETF1', 2, -0.045),
('ETF1', 3, 0.06),
('STOCK1', 1, 0.125),
('STOCK1', 2, 0.095),
('STOCK1', 3, 0.113)
-- Compute compounded return for each instrument
SELECT
InstrumentId,
CompoundedReturn = PRODUCT(1 + RateOfReturn) - 1,
CompoundedReturnPercentage = FORMAT((PRODUCT(1 + RateOfReturn) - 1) * 100, 'N1') || '%'
FROM
Instrument
GROUP BY
InstrumentId

Result:

InstrumentIdCompoundedReturnCompoundedReturnPercentage
BOND10.0980269.8%
ETF10.0932849.3%
STOCK10.37107737.1%

The above query calculates the compounded return for each instrument by taking the product of (1 + RateOfReturn) for all periods and then subtracting 1 to return the CompoundedReturn column. The CompoundedReturnPercentage column shows the same value formatted for display as a percentage with one decimal place.

Using BOND1 as an example, the calculation would be:

(1 + 0.035) = 1.035*Period 1 return
(1 + 0.0275) = 1.0275*Period 2 return
(1 + 0.0325) = 1.0325=Period 3 return
1.098026– 1 =Growth factor (includes the original principal $1)
0.098026=Compounded return (i.e., the percentage gain)
9.8%Isolated profit/loss percentage

Alternative using OVER (PARTITION BY ...)

Like the first example, this version uses windowing with OVER to calculate the compounded return for each individual row.

SELECT
InstrumentId,
Period,
RateOfReturn,
CompoundedReturn = PRODUCT(1 + RateOfReturn) OVER (PARTITION BY InstrumentId) - 1,
CompoundedReturnPercentage = FORMAT((PRODUCT(1 + RateOfReturn) OVER (PARTITION BY InstrumentId) - 1) * 100,'N1') || '%'
FROM
Instrument
ORDER BY
InstrumentId,
Period

Result:

InstrumentIdPeriodRateOfReturnCompoundedReturnCompoundedReturnPercentage
BOND110.03500.0980269.8%
BOND120.02750.0980269.8%
BOND130.03250.0980269.8%
ETF110.08000.0932849.3%
ETF12-0.04500.0932849.3%
ETF130.06000.0932849.3%
STOCK110.12500.37107737.1%
STOCK120.09500.37107737.1%
STOCK130.11300.37107737.1%

Summary

The new PRODUCT function in SQL Server 2025 brings native multiplicative aggregation to T-SQL, eliminating the need for workarounds when calculating the product of a set of numeric values. It supports standard aggregation with GROUP BY, including DISTINCT, as well as analytic calculations using OVER (PARTITION BY ...) to preserve individual detail rows. As we demonstrated with product prices and compounded investment returns, PRODUCT makes calculations that depend on multiplying values across a set simpler and more expressive.

Happy coding!



Read the whole story
alvinashcraft
16 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

.NET 8 and .NET 9 Support Ends November 10th, 2026: Upgrade Now

1 Share
.NET 8 and .NET 9 reach end of support on November 10th, 2026. If you haven't made the move to .NET 10 yet, this post has a number of tips & checklist items to help you get your upgrade planned, tested, and deployed to .NET 10 before the deadline.
Read the whole story
alvinashcraft
30 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

AI is fucking awful (the guide)

1 Share

This weekend, I finished tending my guide on AI that I had planted a seed for in my digital garden.

It includes links to various articles on it’s roles in environmental destruction, labor exploitation, economic failure, degrading critical thinking skills, and fascist empowerment.

I’ve also included my own personal thoughts, and links to various other thought pieces from other people that I’ve found useful or informative.

You can find the guide here.

Read the whole story
alvinashcraft
42 seconds ago
reply
Pennsylvania, USA
Share this story
Delete

Register Pipeline Stages With .NET Dependency Injection

1 Share

Learn how to register ordered pipeline stages with Microsoft DI, choose safe service lifetimes, create background scopes, and avoid captive dependencies.



Read the whole story
alvinashcraft
1 minute ago
reply
Pennsylvania, USA
Share this story
Delete

Android Weekly Issue #742

1 Share
Articles & Tutorials
Sponsored
Debugging mobile apps is weird: intermittent connections, mid-onboarding drop-offs, edge cases on devices you've never tested. bitdrift captures 100% of data, unsampled and in real time, so it’s immediately queryable by engineers and agents. Try bitdrift: mobile observability for the real world.
alt
KMP Bits builds Composure, a shared form-state library adding typed validation, touch/dirty tracking, and cross-field rules.
Jake Wharton uses Molecule to stream live HTML updates from Compose state over WebSockets with kotlinx.html.
Darryl Bayliss explains how to install a JDK via Homebrew so Xcode Cloud can build a KMP library's Gradle build.
Gustavo Fão Valvassori shows how SKIE simplifies consuming Kotlin Flows inside SwiftUI views.
Qamar A Safadi uses memory allocation data to uncover hidden Compose recompositions the Layout Inspector missed, then fixes them.
Zeyad Gasser forks Android's pagecurl library to bring a real page-curl animation to iOS with Compose Multiplatform.
Alex Zhukovich shows how to make screenshot tests deterministic using coil-test fake image loaders or Compose inspection mode.
Nav Singh explores Jetpack Compose's new SelectionState API for programmatic, hoisted text selection control.
Rifqi M Fahmi rebuilds an Android app from a single .class file, adding javac, kotlinc, and Gradle layers by hand.
Place a sponsored post
We reach out to more than 80k Android developers around the world, every week, through our email newsletter and social media channels. Advertise your Android development related service or product!
alt
Libraries & Code
A Jetpack Compose showcase app demonstrating ML Kit barcode scanning, text recognition, and document scanning with CameraX.
A sample app demonstrating Android 16 Live Updates delivery tracking with Notification.ProgressStyle and Jetpack Compose.
A searchable gallery of ready-to-use Jetpack Compose gradients with copyable code for each design.
A FOSS Android compass and navigation app with sensor fusion, live tracking, and offline maps, no ads or tracking.
A Gradle plugin that catches R8 shrinking regressions and lints toxic consumer rules for Kotlin/Android libraries.
A Gradle plugin that turns Compose previews and XML views into a browsable web catalogue of your app's UI.
A Kotlin ORM using KSP-generated data classes and a SQL builder, preserving direct control over SQLite queries.
News
Google details AAOS SDV's security architecture: VM isolation, deny-by-default SELinux, APEX signing, Rust, and DICE-based mesh authentication.
alt
JetBrains updates the Kotlin roadmap, adding Wasm stabilization, Swift Export beta, and a unified Kotlin Toolchain entry point.
JetBrains releases Compose Multiplatform 1.12.0 with an MCP server for AI agents, web font fallback, and a new window/dialog API.
Google Play introduces new memory usage thresholds and a Zero-Tap Sign-In requirement for device migration.
Google Play details its multi-layered defenses and best practices for developers to prevent AI-generated non-consensual intimate content.
Google details how WhatsApp adopted passkeys via Credential Manager API, reaching one billion users with phishing-resistant sign-in.
Videos & Podcasts
Philipp Lackner tests whether test-driven development improves results for AI agent-based Android app development.
Dmitri Chernysh demonstrates using an AGENTS.md file to scaffold Android feature modules ten times faster.
Denis Ambatenne demonstrates using Kotlin LSP and Hot Reload to build KMP apps from Cursor.
Michal Harakal presents SKaiNET, an open-source Kotlin framework bringing on-device machine learning to Kotlin developers.
Firebase livestreams building an offline-capable, spoiler-free book Q&A app using on-device AI and Firestore.
Jeffrey van Gogh explains why using Reflection can cause problems in JVM and Kotlin applications.
The Developers' Bakery marks its 100th episode, reflecting on five years of open source interviews and welcoming two new co-hosts.
Philipp Lackner shows how to set up GitHub Actions CI for Android, from first pipeline to automated code quality checks.
Wojtek Kalicinski demonstrates the Kotlin Build Tools API for reliably integrating the compiler into custom build systems.
Phil Burk explains building cross-platform, low-latency audio for music apps using Kotlin Multiplatform expect/actual classes.
Stevdza-San demonstrates using GraphQL with Apollo Kotlin in an Android project.
sinasamaki rebuilds a striking timer's design and animations in Jetpack Compose using his ChromaDial library.
Read the whole story
alvinashcraft
1 minute ago
reply
Pennsylvania, USA
Share this story
Delete

F# Weekly #35, 2026 — Fabulous 10, .NET Conf 2026 Announced, and C# 15 Preview

1 Share

Welcome to F# Weekly,

A roundup of F# content from this past week:

News

Hey .NET Fans! It’s that time of year again!.NET Conf is back November 10-12, 2026.Spend three days learning from the people who build and use .NET, catching up with the community, and launching .NET 11.Learn more and save the date: msft.it/63328aPzWC#dotNETConf

.NET (@dot.net) 2026-08-25T17:06:02.857Z

Microsoft News

Videos

Highlighted Projects

  • Neftedollar/FsLangMCP — MCP server giving AI coding agents (Claude, Cursor, Copilot) real FCS/FSAC compiler intelligence instead of grepping F# source.
  • vykrum/Hywe — Computational spatial design environment for generating architectural spatial configurations from relational graphs, rules, and constraints (F#/WASM/WebGPU).
  • mfakane/wasm-fcs — F# Compiler Services running in WASM — bringing FCS to the browser.
  • Neftedollar/orleans-fsharp — Idiomatic F# for Microsoft Orleans: computation expressions for grains, streaming, event sourcing, 1700+ tests.
  • TheFellow/fkyeah — F# pipeline engine for multi-stage AI/LLM workflows.
  • tunaxor.me/Kimo — Kimo is a small 3D RPG prototype written in F#. It is inspired by Trickster Online: skills with cast times and cooldowns, status effects, gear, and enemies that patrol, remember you, and flee when hurt.

New Releases

Rather than just keep talking about it, I'll just let you give it a look. This is the current RPG'ish prototype I've been working on.Source Code:tangled.org/tunaxor.me/K…#dotnet #fsharp #monogame #gamdev

Angel Munoz (@tunaxor.me) 2026-08-23T06:54:53.711Z

That’s all for now. Have a great week.

Buy Me A Coffee





Read the whole story
alvinashcraft
1 minute ago
reply
Pennsylvania, USA
Share this story
Delete
Next Page of Stories