我对GDS还是陌生的,到目前为止我很喜欢它。我正在尝试做的是创建一个Google表格,其中包含特定工作的需求和数量,然后使用Data Studio来按需求进行搜索并将数量显示在同一字段中。
我已经模拟了一些我目前拥有的东西的例子:
https://datastudio.google.com/open/1z0SIYa0ucpBiJXf_IQBaIsu61INP71Hc
https://docs.google.com/spreadsheets/d/1eUhE3chM77etyTcv4E7jyB_6vCFxSYArMyF2ptxK180/edit?usp=sharing
如果将数量与物料结合在一起,则将失去在数据工作室中按物料进行搜索的能力。我希望只能有两列,有人在Mat X中键入内容,并且所有与之相关的工作都在同一列中。
我知道我可以通过为每种材料使用N个数量的列来完成类似的事情,并且包含该数量但对于我的应用而言不实际。
谢谢您的时间。
答案 0 :(得分:1)
Data Studio无法筛选Material,因为它无法识别唯一的组件。
我建议您在电子表格中创建第二个表,该表由脚本/宏创建,并按作业列出材料和数量。 该工作表是Data Studio的来源,因此它将启用按Job或Material进行过滤。可以通过运行宏随时更新该表。
如果使用此Excel,则VBA会很容易编写,但是Google Scripts使用Javascript,因此肯定会花我一点时间(尽管其他人会更熟练)来提供代码示例以实现新的电子表格。
Google脚本逻辑为:
对于每个工作
在Data Studio中
更新 该代码实现了以上概述的目标-拥有为GDS服务的第二张表。它获取原始作业信息并构建一张数据表,以标识每个作业的物料和数量的每种组合。该代码可能没有效率那么高,但是在此阶段更重要的是-它可以工作。
三个假设:1)每个作业始终使用一种以上的材料; 2)物料代码不包含空格; 3)数量始终是整数。
快速摘要
可以将一个“主”功能分配给GDS_data工作表上的一个按钮。这使得重建GDS数据极为容易。
这些功能是:
// Convert Job info for GDS
function BuildGDSData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheetByName('jobinfo');// assumes basic job info is on sheet called "jobinfo"
var target = ss.getSheetByName('gds_data');// assumes that the GDS data is build on a sheet called "gds_data"
// Start gds_data from scratch. Delete everything
target.clearContents();
target.clearFormats();
// Get the data range from sheet = jobinfo
var rangeToCopy = source.getRange(1, 1, source.getMaxRows(),source.getMaxColumns());
// Paste the data to the cheet=gds_data
rangeToCopy.copyTo(target.getRange(1, 1));
// Add headings on sheet=gds_data for Material and Qty
target.getRange('C1').setValue('Material');
target.getRange('D1').setValue('Qty');
// Move the cursor to cell B2 on sheet = gds_data- this is the start of the job information
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange('B2:B2');
sheet.setActiveRange(range);
// Call function CountJobs; assign number to jobs to variable "job_count"
var job_count = CountJobs();
// execute loop for the number of jobs
for (var i = 0; i < job_count; i++) {
// Call function CountMaterials; assign the number of materials for the job to variable MatCount
var MatCount = CountMaterials();
// Copy and insert new rows for the job so that there is one row per requirement. Copy the job details onto each new row
// Number of rows to create = for this job, the number of materials minus one. The "one" is row of job information that already exists.
CreateJobRows ((MatCount-1));
// Parse the requirements and copy the results to the Materials and Qty columns
BuildMaterials();
}
}
// Count and return the number of Jobs = number of rows of data minus one. the "one" is the header row,
function CountJobs() {
var numRows = SpreadsheetApp.getActiveSpreadsheet().getLastRow();
var numCols = SpreadsheetApp.getActiveSpreadsheet().getLastColumn();
return (numRows-1);
}
// Count and return the number of Materials for the current job; Quantity = number of commas plus 1
function CountMaterials(){
var activeSheet = SpreadsheetApp.getActiveSheet();
var selection = activeSheet.getSelection();
// get the requirments value for this job
var text = selection.getCurrentCell().getValue();
// use the split command to explode the requirments. Split by comma.
var textArray = text.split(",");
// Couht the number of components created by the split
var Num_Materials = textArray.length;
// Return the number of Components
return Num_Materials;
}
// Create new rows to cater for each requirment on the job. The count variable identifies the number of rows to create
function CreateJobRows(count) {
var sheet = SpreadsheetApp.getActiveSheet();
for (var i = 0; i < count; i++) {
// get the current row number
row = sheet.getActiveCell().getRow();
// insert a new row after the current row
sheet.insertRowAfter(row);
//copy the contents from cells A and B of the current row to the new row
var rangeToCopy = sheet.getRange(row, 1, 1, 2);
rangeToCopy.copyTo(sheet.getRange(row+1, 1));
}
}
// Parse the requirements and copy the results to the Materials and Qty columns
function BuildMaterials(){
var activeSheet = SpreadsheetApp.getActiveSheet();
var selection = activeSheet.getSelection();
// Before you start, get the current row and current column and assign the valuares to variables.
job_row = activeSheet.getActiveCell().getRow();
job_col = activeSheet.getActiveCell().getColumn();
// Get the requirements for this job
var text = selection.getCurrentCell().getValue();
// Split by comma and put the requirments into an array
var textArray = text.split(",");
// Count the number of components in the array
var NumRequirements = textArray.length;
for (var i = 0; i < NumRequirements; i++) {
// establish some variables and ensure that values from a previous loop don't carry over
var req_string = "";
var req_array = [];
var req_data = [];
var qty="";
var material = "";
// get the component; trim just in case
req_string = textArray[i].trim();
// put the component into its own array (req_array)
var req_array = req_string.split(" ");
// get values for quanity and material
qty = req_array[0];
material= req_array[1];
// assign values for quanty and material type to new array. Order of Qty and Material is different.
req_data[0] = material;
req_data[1] = qty;
// create array in format that Google Sheets requires.
var req_results = [req_data];
// define range to copy the results
ResultsRange = activeSheet.getRange((job_row+i), (job_col+1), 1, 2);; // getRange(row, column, numRows, numColumns)
// insert values for Materials and Qty into the respective columns on the relevant row.
ResultsRange.setValues(req_results);
} // repeat for next requirement
// Finished requirements for this job.
// Move the cursor down to the next job (rows=Number of Requirements)
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getRange((job_row+NumRequirements), 2, 1, 1); // getRange(row, column, numRows, numColumns)
sheet.setActiveRange(range);
}