[]
        
(Showing Draft Content)

PIVOTBY

この関数は、数式を使用してデータの要約を作成できる強力なツールです。2つの軸に沿ったグループ化と関連する値の集計をサポートしています。この関数はGROUPBY関数に似ていますが、行と列の両方でデータをグループ化できる追加機能があります。

書式

PIVOTBY(row_fields, col_fields, values, function, [field_headers], [row_total_depth], [row_sort_order], [col_total_depth], [col_sort_order], [filter_array], [relative_to])

引数

有効な引数は次のとおりです。

引数

説明

row_fields (必須)

行をグループ化し、行ヘッダーを生成するために使用される値を含む列指向の配列または範囲。

col_fields (必須)

列をグループ化し、列ヘッダーを生成するために使用される値を含む列指向の配列または範囲。

values (必須)

集計するデータの列指向の配列または範囲。

function (必須)

値を集計する方法を定義するラムダ関数または簡略化されたラムダ(例:SUM、AVERAGE、COUNT)。

field_headers

row_fields、col_fields、およびvaluesにヘッダーが含まれているかどうか、および結果にフィールドヘッダーを返すかどうかを指定します。

row_total_depth

行ヘッダーに合計を含めるかどうかを決定します。

row_sort_order

行をどのように並べ替えるかを示します。

col_total_depth

列ヘッダーに合計を含めるかどうかを決定します。

col_sort_order

列をどのように並べ替えるかを示します。

filter_array

対応するデータ行を考慮するかどうかを示すブール値の列指向の1次元配列。

relative_to

集計関数の第2引数に提供される値を制御します。通常はPERCENTOF関数と共に使用されます。

解説

  • PIVOTBY関数はExcelのインポートとエクスポートをサポートしています。

  • PIVOTBYは動的配列関数で、必要なセル数に自動的に結果を展開します。

サンプル

PIVOTBY (B2:B34,A2:A34,D2:D34,SUM)

次のコードは、データセットに対するPIVOTBY関数の使用例を示しています。

 // 動的配列を有効にします。
 spread.options.allowDynamicArray = true;
 spread.setSheetCount(3);
 let sheet1 = spread.getSheet(0);
 sheet1.name("PIVOTBY Function");

 let data = [
     ["YEAR", "Category", "Product", "Status", "Sales", "Rating"],
     [2023, "Electronics", "Smart TV", "Active", 15000, 4.5],
     [2023, "Fashion", "Designer Jeans", "Discontinued", 8000, 4.7],
     [2024, "Food", "Organic Granola", "Active", 5000, 4.8],
     [2023, "Books", "Bestseller Novel", "Active", 12000, 4.6],
     [2024, "Electronics", "Laptop", "Active", 20000, 4.9],
     [2023, "Beauty", "Skincare Set", "Discontinued", 7000, 4.4],
     [2023, "Home & Garden", "Garden Tools", "Active", 6500, 4.3],
     [2024, "Health", "Fitness Tracker", "Active", 9500, 4.6],
     [2023, "Toys", "Action Figure", "Active", 4800, 4.7],
     [2024, "Automotive", "Car Accessories", "Discontinued", 3200, 4.5],
     [2023, "Sports", "Basketball", "Active", 7600, 4.8],
     [2024, "Office Supplies", "Notebooks", "Active", 11000, 4.4],
     [2023, "Pet Supplies", "Dog Food", "Discontinued", 5600, 4.6],
     [2024, "Music", "Headphones", "Active", 13000, 4.9],
     [2023, "Outdoor", "Camping Tent", "Discontinued", 4400, 4.5],
     [2024, "Jewelry", "Silver Necklace", "Active", 2800, 4.7],
     [2023, "Tools", "Power Drill", "Active", 3900, 4.4],
     [2024, "Baby", "Stroller", "Active", 1700, 4.6],
     [2023, "Kitchen", "Blender", "Active", 2500, 4.8],
     [2024, "Clothing", "Casual Shirt", "Discontinued", 6200, 4.5],
     [2023, "Art", "Oil Paintings", "Active", 1900, 4.7],
     [2024, "Hobbies", "Model Trains", "Active", 3100, 4.4],
     [2023, "Tech Gadgets", "Smart Watch", "Discontinued", 7300, 4.6],
     [2024, "Travel", "Luggage", "Active", 4600, 4.8],
     [2023, "Home Decor", "Wall Clock", "Active", 2200, 4.5],
 ];

 // Sheet1 - PIVOTBY Function
 sheet1.setArray(0, 0, data);
 sheet1.tables.add("table1", 0, 0, data.length, 6, GC.Spread.Sheets.Tables.TableThemes.medium2);
 sheet1.setFormula(2, 8, "=PIVOTBY(B2:B10,A2:A10, E2:E10,SUM)");