Suppose you have a Google Sheets page that has a table like so:
But Type 1
Bug Type 2
Bug_A
Bug_C
Bug_B
Bug_D
Bug_D
I am trying to create a bar graph that graphs the number of instances of a bug type. The data of each bug is not an integer, which means I cant map integer data like one normally would when creating bar graphs with Google Sheets API.
It seems that with the Google Sheets Python API, you can only use series' data sources with row and column indexes.
'series': [
{
'series': {
'sourceRange': {
'sources': [
{
'sheetId': 636584873,
'startRowIndex': 1,
'endRowIndex': 2,
'startColumnIndex': 0,
'endColumnIndex': len(table_values)
}
]
}
}
}
]
Related
Is it possible to order results of grouped items by the calculation results for each group? It seems that when I set the initialSort (or when I don't)it sorts by the order of the items within each group, rather than by the total calculation of each group.
For example, if I have data that looks something like this:
[
{id:1, company:"company 1", quantity:"10"},
{id:2, company:"company 1", quantity:"10"},
{id:3, company:"company 1", quantity:"10"},
{id:4, company:"company 2", quantity:"20"},
{id:5, company:"company 2", quantity:"1"},
{id:6, company:"company 2", quantity:"1"},
{id:7, company:"company 3", quantity:"9"},
{id:8, company:"company 3", quantity:"9"},
{id:9, company:"company 3", quantity:"9"},
]
I would end up with groups ordered:
Company 2: 22 // Highest qty 20
company 1: 30 // Highest qty 10
company 3: 27 // Highest qty 9
What I am trying to get is:
company 1: 30
company 3: 27
Company 2: 22
I can see the calculation results, but I'm not sure how to resort the groups, assuming it's possible. If anyone can point me in the right direction I will be quite grateful.
Rows can only be sorted according to a field stored in the row data.
Rows are sorted individually and then grouped, with groups appearing in the order of the sorted data.
In order to sort your table in this way, you would need to analyse your row data first before ingesting it into the table, and then set a field on each row with the desired order for the group that contains it.
The other option is to manually specify the groups you want using the groupValues option, with this approach you specify the exact groups you want and the order they should appear:
groupValues:[["male", "female", "smizmar"]]
Thanks Oli for pointing me in the direction of 'groupValues'. I ended up writing a function that uses the calcResults to get the sort order I want and then push them into groupValues to get the ordering I'm looking for.
const sortByGroupCalc = ( thisTable, thisSortField, thisSortDirection ) => {
// Temp arrays
let tempCalcArray = [];
let tempSortArray = [];
// Get calculation results
const calcResults = thisTable.getCalcResults();
// Populate Array with key:value pairs from the caculation results
for( const [key, value] of Object.entries(calcResults)) {
tempCalcArray.push([key, value.top[thisSortField]])
};
// Sort the object by value and direction and then create an array of the keys
tempCalcArray
.sort(function(a, b) {
if( thisSortDirection === 'asc' ) {
return a[1] - b[1];
} else {
return b[1] - a[1];
}})
.map(
x => tempSortArray.push(x[0])
);
// Set group order according to sort order
thisTable.setGroupValues([tempSortArray]);
}
I'm calling it in the dataSorted function. It's not perfect for all occasions, I imagine. But it seems to do what I need.
Thanks again.
I have a PowerApps form connected to a SharePoint Online list. My SharePoint list titled "Log" has a multi-select Choice column named "Service", which appears in PowerApps as a combo-box. The user can select 1 or more "Services" from this combo-box. Based on the selection of services, a number of related "Agencies" should appear in a Gallery on the form. The Agencies are defined against each Service in the Services list.
Log List:
Services: Multi-select lookup
Service List:
Title
Agency (Multi-select Choice, all possible agencies for this Service)
While I can get the selected services from the combo box, the problem is that I am unable to retrieve the values from the Agency multi-select Choice field in the same list. What I have tried is to get the selected Services from the dcvServices control (into SelectedServices) and then collect the related Agency values (into AvailableAgencies) during the OnSelect of the Service dropdown:
ClearCollect(SelectedServices, Filter([#Service], Title in dcvServices.SelectedItems.Value));
ClearCollect(AvailableAgencies, SelectedServices.Agency);
When I try to hook up my Gallery control to the AvailableAgencies collection, I can't quite getthe Agency values to display. I get the following error:
Let's walk through an example, which should shed some light on this problem. If my Service list has these values:
And the services 1 and 4 are selected in the combo box:
Then the expression ClearCollect(SelectedServices, Filter(Service, Title in dcvServices.SelectedItems.Value)) will assign to the SelectedServices collections two items (Service1, Service 4), each of them having a list of agencies associated with it.
If we try to collect the agencies in a separate collection as is, with the expression ClearCollect(AvailableAgencies, SelectedServices.Agency), you will not have the individual agencies in the collection; instead, you will have two records, each of them with a collection itself:
[
Agency: [ { Value: "Agency 1" }, { Value: "Agency 2" }, { Value: "Agency 3" } ],
Agency: [ { Value: "Agency 1" }, { Value: "Agency 4" }, { Value: "Agency 7" } ]
]
And if you have this collection in a gallery, and try to display the value of the agency in a label (which requires a single text value), this won't work (as you stated):
ThisItem.Agency.Value
Because this is not a single text value, but a collection of them (for example, the first item would be the collection of agencies 1,2,3). You could show all values for that specific record using the Concat function, as shown below:
This may not be what you need; if you want all of the individual agencies that are associated with the selected services, you will need a different expression:
Clear(AvailableAgencies2);
ForAll(
SelectedServices,
Collect(AvailableAgencies2, ThisRecord.Agency.Value))
And with that you will have the agencies only in your collection:
Notice that since both service 1 and 4 were associated with the Agency 1, it appears twice. If you don't want that, you can use the Distinct function to filter any repeated values out:
Clear(AvailableAgencies2);
ForAll(
SelectedServices,
Collect(AvailableAgencies2, ThisRecord.Agency.Value));
ClearCollect(AvailableAgencies3, Distinct(AvailableAgencies2, Value))
And that should give you the list of unique agencies associated with the selected services.
I am working on a project where I need to collect data from an API, store them in a matrix and set that data in a Google Sheet using the Google-Sheets-APIv4 with Node.js. Two key in that API are object.start_date and object.end_date which return date strings in the format for e.g "2021-09-22" ie. yyyy-mm-dd. I want to convert that date to dd/mm/yyyy format. The function I have implemented for the same is:
function changeDateFormat(dateString){
let a=dateString.split('-');
let t=a[0];
a[0]=a[2];
a[2]=t;
//console.log(a.join('/'));
return `${a.join('/')}`;
}
The code works fine and I have used it in the manner shown below:
let checkin=`${changeDateFormat(`${tenancy.start_date}`)}`;
console.log(checkin);
let checkout=`${changeDateFormat(`${tenancy.end_date}`)}`;
console.log(checkout);
tenancy in the code above is an object. The output that I get in the console is
which is the desired format, which shows that algorithm for changing date is working fine too.
Also, my code for adding the data in the sheet is
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range:"MySheet!A2:AC",
valueInputOption:"USER_ENTERED",
resource: {values : newData}
/*newData is a 2-D array where each row has several data fields in the form newData[i]=[propertyName,id,......,check-in,checkout,.......]*/
});
However, when I add the data in the sheet, the date fields are entirely jumbled up where some have the desired dd/mm/yyyy format while others have the same yyyy-mm-dd format as shown in the image
I am not being able to solve the problem as I cannot find any error in the code either but the output is completely jumbled as it's working in some cells but not working in other cells. What might be a possible workaround for this problem? I will gladly provide any other information or data regarding the problem or my code if needed. Thanks!
I believe your goal and your situation as follows.
You want to set the number format of the cells to dd/mm/yyyy.
You want to achieve this using googleapis for Node.js.
You have already been able to get and put values for Google Spreadsheet using Sheets API.
Modification points:
For example, when the values of [["2021-01-02", "02/01/2021"]] are put to the Spreadsheet using the method of "spreadsheets.values.append" in Sheets API with valueInputOption of USER_ENTERED, each value is put as the date object. But it seems that the number format is different.
In order to use the same number format, in this answer, I would like to set the number format of dd/mm/yyyy to the cells using the method of "spreadsheets.batchUpdate".
When above points are reflected to your script, it becomes as follows.
Modified script:
Please set the value of sheetId.
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "MySheet!A2:AC",
valueInputOption: "USER_ENTERED",
resource: { values: newData },
});
const sheetId = "###"; // <--- Please set the sheet ID of "MySheet".
const resource = {
auth,
spreadsheetId,
resource: {
requests: [
{
repeatCell: {
range: {
sheetId: sheetId,
startRowIndex: 1,
startColumnIndex: 12,
endColumnIndex: 15,
},
cell: {
userEnteredFormat: {
numberFormat: {
pattern: "dd/mm/yyyy",
type: "DATE",
},
horizontalAlignment: "RIGHT", // <--- Added
},
},
fields: "userEnteredFormat",
},
},
],
},
};
await googleSheets.spreadsheets.batchUpdate(resource);
When above modified script is run, the number format of the columns "M" to "O" is changed to dd/mm/yyyy. This is from your sample image.
If you want to modify the format and range, please modify above script.
And, at above script, the batchUpdate method reflects all rows of the columns "M" to "O". So I think that in this case, this batchUpdate method might be able to achieve your goal by only one time running.
References:
Method: spreadsheets.values.append
Method: spreadsheets.batchUpdate
RepeatCellRequest
Im using Azure Search
I have the data structure below
[
{
"id": "7c064374-73ea-4d0c-c363-2801887b07cf",
"companies": [
{
"companyId": "6f8d235e-69b7-42f9-9917-79411754fef0",
"companyName": "Company"
}
]
}
]
If I want to find all the entries where a guid exists in accounts the filter is
$filter=companies/any(c: c/companyId eq 'value to find')
What is the syntax for getting only entries where value to find is NOT in the companies list?
$filter=companies/any(c: c/companyId ne 'value to find')
Will not work because it will return any entries in the index that contain a company id that is not the id which is enough to to bring a entry back if an entry has 2 companies, one that matches the criteria and one that doesnt
Paul
https://learn.microsoft.com/en-us/azure/search/search-query-odata-collection-operators
$filter=companies/all(c: c/companyId ne 'value to find')
basically I have table (8 rows x 3 columns) within the Google slides presentation, that I want to change background color to via the API.
First item of my list of rgb color values:
cons_data_lst[0][1][-1]
>>> [0.5882353, 0.7764706, 0.4862745]
My function to produce a request body:
def update_table_cell_colors(color_list):
req = [{
'updateTableCellProperties':{
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2,
},
'rowSpan': 1,
'columnSpan': 1,
},
'tableCellProperties':{
'tableCellBackgrounFill':{
'solidFill':{
'color':{
'rgbColor':{
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}}
}}} ]
return req
When I send batch update to presentation I receive the following error:
HttpError: https://slides.googleapis.com/v1/presentations/1dzxYYPuqTM3VhwaR93Ep2jj_9Y2NCkSBsVBnmN6lcOs:batchUpdate?alt=json
returned "Invalid JSON payload received. Unknown name
"table_cell_backgroun_fill" at
'requests[0].update_table_cell_properties.table_cell_properties':
Cannot find field.". Details: "[{'#type':
'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations':
[{'field':
'requests[0].update_table_cell_properties.table_cell_properties',
'description': 'Invalid JSON payload received. Unknown name
"table_cell_backgroun_fill" at
\'requests[0].update_table_cell_properties.table_cell_properties\':
Cannot find field.'}]}]">
Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?
Thank you.
How about this answer?
A1:
In this section, it explains about the reason of the error.
Modification points:
From the error message of Unknown name "table_cell_backgroun_fill" at 'requests[0].update_table_cell_properties.table_cell_properties', it is found that the property name of tableCellBackgrounFill is a spelling mistake. Please modify to tableCellBackgroundFill.
At updateTableCellProperties, the property of fields is required to be used. In your case, how about adding "fields": "tableCellBackgroundFill"? You can also use 'fields': '*'.
When these modifications are reflected to your request body, it becomes as follows.
Modified request body:
req = [
{
'updateTableCellProperties': {
'objectId': 'obj_id',
'tableRange': {
'location': {
'rowIndex': 1,
'columnIndex': 2
},
'rowSpan': 1,
'columnSpan': 1
},
'tableCellProperties': {
'tableCellBackgroundFill': { # Modified
'solidFill': {
'color': {
'rgbColor': {
'red': color_list[0],
'green': color_list[1],
'blue': color_list[2],
}
}
}
}
},
'fields': 'tableCellBackgroundFill' # Added
}
}
]
Before you use this script, please check the variables of color_list and 'obj_id',
A2:
In this section, it explains about the question 2 of Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?.
In your question, you say I have table (8 rows x 3 columns) at the top of your question. But at Given a list of different rgb color values, how can I create a request body to update all columns (1 to 2) row (there are 8) text background color ?, you say columns (1 to 2). I'm confused about this. So I would like to suppose as follows.
Your table has 8 rows and 2 columns.
You want to change the background color of all columns and rows with one color.
The sample request body is as follows.
Sample request body:
req = [
{
"updateTableCellProperties":
{
"objectId": "obj_id",
"tableRange":
{
"location":
{
"rowIndex": 0,
"columnIndex": 0
},
"rowSpan": 8,
"columnSpan": 2
},
"tableCellProperties":
{
"tableCellBackgroundFill":
{
"solidFill":
{
"color":
{
"rgbColor":
{
"red": color_list[0],
"green": color_list[1],
"blue": color_list[2]
}
}
}
}
},
"fields": "tableCellBackgroundFill"
}
}
]
rowIndex and columnIndex are the start cell.
"rowIndex": 0 and "columnIndex": 0 means the cell "A1".
rowSpan and columnSpan are the number of rows and columns.
"rowSpan": 8 and "columnSpan": 2 means 8 rows and 2 columns. By this, the background colors of cells "A1:B8" are changed.
If your table is 8 rows and 3 columns, and you want to change all cells, please set them as follows.
"rowIndex": 0, "columnIndex": 0 and "rowSpan": 8, "columnSpan": 3
If you want to change the special background color every cell, it is required to create the array of request body for each cell. Please be careful this.
Note:
This answer supposes that you have already been able to put and get values for Google Slides using Slides API.
References:
UpdateTableCellPropertiesRequest
TableCellProperties
If I misunderstood your question and this didn't resolve your issue, I apologize.