[]
This function is used to calculate the percentage of a subset of data relative to the entire dataset. It is particularly useful when combined with the GROUPBY and PIVOTBY functions to return percentages.
PERCENTOF(data_subset, data_all)
The function has following arguments.
Argument | Description |
---|---|
data_subset (Required) | The values in the subset of data you want to analyze. |
data_all (Required) | The values that make up the entire set. |
PERCENTOF(Sales_2019, Total_Sales)
The following code shows the usage of PERCENTOF function on a set of data.
// Allow the Dynamic Array to True
spread.options.allowDynamicArray = true;
spread.setSheetCount(3);
let sheet3 = spread.getSheet(2);
sheet3.name("PERCENTOF Function");
let data2 = [
["Product", "Sales"],
["Bib-Shorts", 7600],
["Bike Racks", 56100],
["Bottom Brack", 2100],
["Brakes", 11100],
["Gloves", 55900],
["Lights", 59600],
["Locks", 74800],
["Shorts", 48300],
["Socks", 9700],
["Tights", 61400],
["Vests", 7000],
["Wheels", 48500]
]
// Sheet3 - PERCENTOF Function
sheet3.setArray(0, 0, data2);
sheet3.tables.add("table3", 0, 0, data2.length, 2, GC.Spread.Sheets.Tables.TableThemes.medium2);
sheet3.setValue(1, 8, "Bib-Shorts, Bike Racks and % of all");
sheet3.setFormatter(2, 8, "0.00%");
sheet3.setFormula(2, 8, "=PERCENTOF(B2:B3,B2:B13)");