Avg(MDX)

集合を評価し、集合内のセルの空でない値の平均を、その集合内の測度または指定された測度で平均した値を返します。

構文

  
Avg( Set_Expression [ , Numeric_Expression ] )  

引数

Set_Expression
集合を返す有効な多次元表現(MDX)式

Numeric_Expression
有効な数値式で、通常は数を返すセル座標の多次元表現(MDX)式です。

Remarks

空のタプルの集合や空集合が指定されている場合、 Avg 関数は空の値を返します。

Avg関数は、指定された集合内のセル間の値の合計をまず計算し、その集合内の空でないセル数を割ることで、空でないセルの値の平均を計算します。

Analysis Servicesは、数値の集合の平均値を計算する際にnullを無視します。

特定の数値表現(通常は測度)が指定されていない場合、 Avg 関数は現在のクエリ文脈内で各測度を平均化します。 特定の測度が提供された場合、 Avg 関数はまずその測度を集合上で評価し、その後指定された測度に基づいて平均を計算します。

計算されたメンバー文で CurrentMember 関数を使用する場合、そのようなクエリ文脈では現在の座標にデフォルトの測度が存在しないため、数値式を指定する必要があります。

空セルの包含を強制するには、アプリケーションは CoalesceEmpty 関数を使用するか、空の値に対して0(0)の値を供給する有効な Numeric_Expression を指定する必要があります。 空セルの詳細については、OLE DBのドキュメントをご覧ください。

Examples

以下の例は、指定された集合上の測度の平均値を返します。 指定された測度は、指定された集合のメンバーのデフォルト測度か、特定の測度のいずれかであることに注目してください。

WITH SET [NW Region] AS  
{[Geography].[State-Province].[Washington]  
, [Geography].[State-Province].[Oregon]  
, [Geography].[State-Province].[Idaho]}  
MEMBER [Geography].[Geography].[NW Region Avg] AS  
AVG ([NW Region]  
--Uncomment the line below to get an average by Reseller Gross Profit Margin  
--otherwise the average will be by whatever the default measure is in the cube,  
--or whatever measure is specified in the query  
--, [Measures].[Reseller Gross Profit Margin]  
)  
SELECT [Date].[Calendar Year].[Calendar Year].Members ON 0  
FROM [Adventure Works]  
WHERE ([Geography].[Geography].[NW Region Avg])  

以下の例は、2003会計年度の各月の日々を算出した Measures.[Gross Profit Margin] 指標の日平均を Adventure Works キューブから返します。 Avg関数は、[Ship Date].[Fiscal Time]階層の各月に含まれる日数の集合から平均を算出します。 計算の最初のバージョンは、平均から売上が記録されていない日を除外したAvgのデフォルトの動作を示し、2つ目のバージョンは売上がなかった日を平均に含める方法を示しています。

WITH MEMBER Measures.[Avg Gross Profit Margin] AS  
Avg(  
Descendants(  
[Ship Date].[Fiscal].CurrentMember,  
[Ship Date].[Fiscal].[Date]  
),  
Measures.[Gross Profit Margin]  
), format_String='percent'  
MEMBER Measures.[Avg Gross Profit Margin Including Empty Days] AS  
Avg(  
Descendants(  
[Ship Date].[Fiscal].CurrentMember,  
[Ship Date].[Fiscal].[Date]  
),  
CoalesceEmpty(Measures.[Gross Profit Margin],0)  
), Format_String='percent'  
SELECT  
{Measures.[Avg Gross Profit Margin],Measures.[Avg Gross Profit Margin Including Empty Days]} ON COLUMNS,  
[Ship Date].[Fiscal].[Fiscal Year].Members ON ROWS  
FROM  
[Adventure Works]  
WHERE([Product].[Product Categories].[Product].&[344])  

以下の例は、2003会計年度の各学期の日々を算出した Measures.[Gross Profit Margin] 指標の日平均値を Adventure Works キューブから返します。

WITH MEMBER Measures.[Avg Gross Profit Margin] AS  
   Avg(  
      Descendants(  
         [Ship Date].[Fiscal].CurrentMember,   
            [Ship Date].[Fiscal].[Date]  
      ),   
      Measures.[Gross Profit Margin]  
   )  
SELECT  
   Measures.[Avg Gross Profit Margin] ON COLUMNS,  
      [Ship Date].[Fiscal].[Fiscal Year].[FY 2003].Children ON ROWS  
FROM  
   [Adventure Works]