$query->registerRuntimeField("store",[
"data_type" => "\Bitrix\Catalog\StoreProductTable",
'reference' => [
'this.ID' => 'ref.PRODUCT_ID'
],
]);
$query->registerRuntimeField("DETAIL_AMOUNT",[
"data_type" => "integer",
"expression" => array("sum(%s)", "store.AMOUNT")
]);