Avg(MDX)

집합을 계산하고 집합의 측정값이나 지정된 측정값에 대해 집합에서 비어 있지 않은 셀 값의 평균을 계산하여 반환합니다.

구문

Avg( Set_Expression [ , Numeric_Expression ] )

인수

  • Set_Expression
    집합을 반환하는 유효한 MDX 식입니다.

  • Numeric_Expression
    숫자를 반환하는 셀 좌표의 유효한 숫자 식으로서, 일반적으로 MDX 식입니다.

주의

일련의 빈 튜플 또는 빈 집합이 지정되면 Avg 함수가 빈 값을 반환합니다.

Avg 함수는 먼저 지정된 집합에서 셀 값의 합계를 계산하고 계산된 합계를 지정된 집합의 비어 있지 않은 셀 개수로 나눠서 지정된 집합의 비어 있지 않은 셀 값에 대한 평균을 계산합니다.

[!참고]

Analysis Services는 숫자 집합의 평균값을 계산할 때 Null을 무시합니다.

특정 숫자 식(대개 측정값)을 지정하지 않은 경우 Avg 함수는 현재 쿼리 컨텍스트 내에서 각 측정값의 평균을 계산합니다. 특정 측정값이 지정된 경우 Avg 함수는 먼저 집합의 측정값을 계산하고 지정된 측정값을 기준으로 평균을 계산합니다.

[!참고]

CurrentMember 함수를 계산 멤버 문에 사용하는 경우 해당 쿼리 컨텍스트에 현재 좌표에 대한 기본 측정값이 없으므로 숫자 식을 지정해야 합니다.

빈 셀을 강제로 포함시키려면 응용 프로그램에서 CoalesceEmpty 함수를 사용하거나 빈 값에 대해 0 값을 제공하는 유효한 Numeric_Expression을 지정해야 합니다. 빈 셀에 대한 자세한 내용은 OLE DB 설명서를 참조하십시오.

다음 예에서는 지정된 집합의 측정값 평균을 반환합니다. 측정값은 지정된 집합 멤버의 기본 측정값이나 지정된 측정값일 수 있습니다.

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])

다음 예는 Adventure Works 큐브로부터 2003 회계 연도에서 각 월의 일에 대해 계산된 Measures.[Gross Profit Margin] 측정값의 일일 평균을 반환합니다. Avg 함수는 [Ship Date].[Fiscal Time] 계층의 각 월에 포함된 일 집합으로부터 평균을 계산합니다. 첫 번째 버전의 계산에서는 평균에서 매출을 기록하지 않은 일을 제외하는 기본 Avg 동작을 보여 주고, 두 번째 버전에서는 평균에 매출이 없는 일을 포함하는 방법을 보여 줍니다.

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])

다음 예에서는 Adventure Works 큐브로부터 2003 회계 연도에서 각 반기의 일에 대해 계산된 Measures.[Gross Profit Margin] 측정값의 일일 평균을 반환합니다.

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]

참고 항목

참조

MDX 함수 참조(MDX)