테이블 시트는 필드뿐 아니라 수식 및 관련 필드도 그룹 또는 슬라이스 열로 지원합니다.
수식 또는 관련 필드를 그룹 옵션으로 설정할 수 있습니다.
tableSheet.groupBy([
{
caption: 'Company Name',
field: 'Customers.CompanyName', // grouping related field for company name of the customer
},
{
caption: 'Year',
field: '=YEAR([@OrderDate])', // grouping formula field for year of the order date
},
{
caption: 'Freight Level',
field: '=IFS([@Freight]<30,0,AND([@Freight]>=30,[@Freight]<60),1,[@Freight]>60,2)', // grouping formula field for numerical range
style: { formatter: `=SWITCH(@,0,"Low",1,"Medium",2,"High","no match")` },
}
])
슬라이스 열은 수식 및 관련 필드를 동일한 방법으로 지원할 수 있습니다.
tableSheet.groupBy([
{
caption: 'Year',
field: '=YEAR([@OrderDate])',
summaryFields: [
{
formula: '=SUM([Freight])',
slice: 'Customers.CompanyName' // slice related field for company name of the customer
},
{
formula: '=SUM([Freight])',
slice: '=MONTH([@OrderDate])' // slice formula field for month of the order date
},
]
}
])
DATEPART 수식을 사용하여 필드를 날짜 형식별로 그룹화할 수 있습니다. 구문은 다음과 같습니다.
=DATEPART(date_value, format_string, [week_num_type])
인수 | 설명 |
---|---|
date_value | (필수) 날짜 값. |
format_string | (필수) 날짜의 서식 문자열. |
[week_num_type] | (선택 사항) WEEKNUM의 두 번째 인수와 동일. |
DATEPART 수식의 서식 문자열 및 샘플:
서식 | 결과 | 설명 |
---|---|---|
yyyyQ | 20214 | 숫자: 한 자릿수(분기 숫자/이름) |
yyyyQQ | 202104 | 숫자: 두 자릿수 + 제로 패드 |
yyyyQQQ | 2021Q4 | 약어 |
yyyy QQQQ | 2021 4분기 | 넓게 |
YYYY w | 2021 8 | 숫자: 최소 자릿수(연도의 주)(숫자). 패턴에서 연도와 함께 사용할 때 연도 필드의 경우 'Y' 사용.) |
YYYY ww | 2021 08 | 숫자: 두 자릿수, 필요한 경우 제로 패드 |
MM-yyyy | 09-2021 | 셀 서식 지정에서 부분 날짜 포맷터 제공 |
CALCULATE 및 REMOVEFILTERS 수식을 사용하면 그룹 컨텍스트를 확장할 수 있습니다. 구문은 다음과 같습니다.
=CALCULATE(formula_string, expand_context)
인수 | 설명 |
---|---|
formula_string | (필수) 수식은 expand_context의 컨텍스트로 평가합니다. |
expand_context | (필수) expand_context는 REMOVEFILTERS의 컨텍스트입니다. |
=REMOVEFILTERS([ group_field_string [, group_field_string [, … ] ] ])
인수 | 설명 |
---|---|
[group_field_string] | (선택 사항) 그룹 필드는 확장되는 범위를 나타냅니다. |
CALCULATE 수식은 summaryFields 섹션에서만 사용해야 하며, REMOVEFILTERS는 REMOVEFILTERS와 CALCULATE의 조합에만 사용해야 합니다.
tableSheet.groupBy([
{
caption: "Company Name", field: "Customers.CompanyName",
},
{
caption: "Year Quarter", field: `=DATEPART([@OrderDate],"yyyyQQQ")`,
},
{
caption: "Ship Via", field: "ShipVia",
summaryFields: [
{
formula: `=SUM([Freight]) / CALCULATE( SUM([Freight]), REMOVEFILTERS("ShipVia"))` // ratio of sum of freight under freight level to sum of freight under ship name
},
{
formula: `=SUM([Freight]) / CALCULATE( SUM([Freight]), REMOVEFILTERS("ShipVia", "=DATEPART([@OrderDate],""yyyyQQQ"")"))` // ratio of sum of freight under freight level to sum of freight under year quarter
},
{
formula: `=SUM([Freight]) / CALCULATE( SUM([Freight]), REMOVEFILTERS())` // ratio of sum of freight under freight level to sum of freight under all records
},
]
}
]);