다음을 통해 공유


평균(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)