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?
Fact_Qty Sold: ApplySimple("Count #0", QTY_SOLD)
Fact_Qty Sold: ApplySimple("Sum #0", QTY_SOLD)
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, |
|
select a11.ORDER_ID ORDER_ID, |
|