ApplyAgg

2008. 2. 20. 16:24

The Apply Functions: <---- Apply 함수에 대한 간략한 설명

Each type of custom sub-expression/function call is represented by a specialized Apply function. There are several predefined Apply functions that can be used where regular predefined functions of the same type are used.

  • ApplySimple where simple (e.g. arithmetic operators) are used.
  • ApplyAgg where aggregate functions (Sum, Max, etc.) are used.
  • ApplyRelative where OLAP (ranking, etc.) functions are used.
  • ApplyComparison where comparison operators (>=, <, Like, etc.) are used.
  • ApplyLogic where logical operators (And, Or, etc.) are used.

이중에서 MSTR 개발을 해 보신 분이라면 ApplySimple 함수를 사용해 보신적이 있을것입니다.

주로 어트리뷰트를 case 함수 같은 것을 사용한 사용자 SQL로 정의할때 많이 사용하는 함수입니다.


하지만 ApplyAgg 함수는 자주 사용하지는 않지만 유용한 기능이 있습니다.


먼저 간단하게 상수값 으로 사용이 가능합니다.


어떤 어트리뷰트에도 상관없이 상수값을 보고서에서 표시해 주고자 할때 사용이 가능합니다.


새로 만들기>메트릭을 선택한 다음....


ApplyAgg("#0", 1) {~}


수식으로 만들면 됩니다.


간단하지만 다양하게 응용해서 사용가능하겠죠...


좀 더 응용을 해서 실제로 유용하게 사용이 가능한 시나리오를 소개하겠습니다.


예를 들어...


동일한 메트릭으로 특정 팩트테이블에서는 SUM 을 수행하고 다른 팩트 테이블에서는 Count 나 Max 를 수행하게 하는 것입니다.


비즈니스 시나리오를 얘기하자면...


"계좌Master" 테이블과 "일별고객수" 팩트테이블이 있다고 가정할때...


일별고객수에서는 "sum(고객수)" 를 수행하여 "일별/고객수"를 조회하는 보고서에서

"계좌종류" 어트리뷰트로 드릴을 수행하여 "일별/계좌종류/고객수"를 조회하고자 한다면...


계좌 Master 에서는 "count(distinct 고객ID)"를 수행해야 합니다.


이런 비즈니스 시나리오가 있을때 간단하게 처리할수 있는 함수로 ApplyAgg 함수입니다.


일단 "고객수" 팩트를 먼저 만들때

일별고객수 팩트테이블에는 ApplySimple("SUM(#0)", 고객수) 이용해서 만들고

(여기서 고객수는 일별고객수 테이블의 컬럼명)


계좌Master 테이블에서는 ApplySimple("COUNT(DISTINCT #0)", 고객ID) 를 이용하여 서로 다른 형태로 만듭니다.

(여기서 고객ID 는 계좌테이블의 컬럼명)


그리고 메트릭을 만들때...

ApplyAgg("#0", 고객수)

형식으로 고객수 팩트를 이용해서 만들어서 사용하면 됩니다.

(여기서 고객수는 팩트명)

아래의 예제는 MSTR Support 에서 퍼온 "Tutorial" 예제입니다.

========================================================================================================

What is an adaptive metric in MicroStrategy?

TN5200-75x-0459, adaptive metric, ApplySimple, ApplyAgg
It is sometimes desirable to choose a different metric dynamically depending on the database table against which the MicroStrategy SQL Engine issues SQL if the two tables contain a column with the same name with values at different levels. A practical example would involve the Sum() and Count() metrics where users may want to issue Count() against the column in a detail level table while they may want to issue Sum() against the same column in the corresponding aggregate level table.
This can be accomplished using a combination of ApplySimple() and ApplyAgg() functions at the Fact and Metric definitions, respectively. The following example is created within the MicroStrategy Tutorial project, specifically using the ORDER_DETAIL and ORDER_FACT tables.
Create a Fact using two expressions with ApplySimple() definitions as follows:

    Fact_Qty Sold: ApplySimple("Count #0", QTY_SOLD)

against the ORDER_DETAIL table:

사용자 삽입 이미지

Fact_Qty Sold: ApplySimple("Sum #0", QTY_SOLD)

against the ORDER_FACT table:

사용자 삽입 이미지

Create a metric using the ApplyAgg() function on Fact_Qty Sold as follows:

M_Qty Sold:ApplyAgg("#0", Fact_Qty Sold)

사용자 삽입 이미지


The MicroStrategy SQL Engine then correctly selects the underlying form expression for the Fact depending on the corresponding source table:

SQL Report Definition

    select a11.ORDER_ID ORDER_ID,
    a11.SHIP_DATE SHIP_DATE,
    Sum a11.QTY_SOLD WJXBFS1
    from ORDER_FACT a11
    group by a11.ORDER_ID,
    a11.SHIP_DATE

사용자 삽입 이미지
 

    select a11.ORDER_ID ORDER_ID,
    a11.PROMOTION_ID PROMOTION_ID,
    a12.PROMO_SALE PROMO_SALE,
    Count a11.QTY_SOLD WJXBFS1
    from ORDER_DETAIL a11,
    LU_PROMOTION a12
    where a11.PROMOTION_ID = a12.PROMO_SALE_ID
    group by a11.ORDER_ID,
    a11.PROMOTION_ID,
    a12.PROMO_SALE

사용자 삽입 이미지
 



Posted by anal
:
BLOG main image
데이터베이스의 품질과 분석에 대한 정보를 공유 by anal

카테고리

분류 전체보기 (121)
Daily Report (7)
MCMs (0)
01.사업기회발굴 (0)
02.사업기회선정 (0)
03.예비사업평가 (0)
04.사업화 (0)
A0. Information for Open Mi.. (0)
A1. Data Standardization (23)
A2. Modeling (1)
A3. Data Quality (0)
A4. DataBase (5)
A5. DataWare House (0)
A6. Data Mart (0)
A7. Data Analysis (0)
A8. OLAP (4)
A9. ETL (0)
B1. Enterprise Portal (0)
B2. Methodology (0)
B3. Customer Relationship M.. (1)
C1. SAP (3)
C2. BSC (0)
C3. SOA (0)
C4. Big Data (3)
C5. R (1)
P0. Projects (3)
V0.신사업관련 (2)
Y0. IELTS (3)
Z0. Et Cetera (58)
[Book] BI 2.5 Guide (3)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :