I have a function in Google Sheets to Query my data, and it works perfectly fine, until I try to order it.
The function is...
=query('Master Accounts List'!A1:I,"select A,B,C,E,F where E='"&A3&"' OR C="&A2)
As soon as I attempt to add order by A desc it gives me a Formula Parse Error.
Any help would be greatly appreciated.
Please try:
=query('Master Accounts List'!A1:I,"select A,B,C,E,F where E='"&A3&"' OR C='&A2&' order by A desc")
Related
I need to be able to automatically update a google sheet file every time an order is placed through WooCommerce.
I've found the solution below, but using this each individual item ordered is listed as a new row. I'd like the order to be grouped under the order number and the item quantities separated into appropriate columns instead.
https://www.tychesoftwares.com/export-woocommerce-orders-to-google-sheets-in-realtime/
Below is a Google Sheet we are manually updating at present to show you what i mean.
Example
Is there a way to send the WooCommerce orders directly through to Google Sheets in this format?
Thanks so much in advance for any advice!
Yes it looks possible.
I know nothing about WooCommerce, but I believe you can sort out the received data in any way you want.
Look, the last line in their script appends the received data as a new row:
sheet.appendRow([timestamp,order_number,order_created,order_status]);
As far as I can see, the data contains the four elements:
timestamp
order_number
order_created
orders_status
Instead, you can put these elements into any cell on your table. Something like this, for example:
var ss = Spreadsheet.GetActiveSheet();
ss.getRange('A10').setValue(timestamp); // timestamp goes to A10
ss.getRange('B20').setValue(order_number); // order_number goes to B20
ss.getRange('C30').setValue(order_created + order_status); // created + status go to C30
The same way you can add any of these elements to some existing value in some cell, etc. For example:
var old_value = ss.getRange('A2').getValue(); // get value from the cell A2
var new_value = old_value + order_number; // add with order_number
ss.getRange('A2').setValue(new_value); // put the sum back into the cell A2
The main problem is up to you. You have to figure out:
what exactly the elements you're receiving (number, names)
how exactly you want to sort them out (what to add to what... what to put where... etc)
I can't understand it from the example picture.
Here is some reference documentation on Apps Script:
Main Page - Introducing Apps Script.
Sheets Guide - Introduction to Sheets with Apps Script.
Sheets Reference - Where you will find all the details of everything you can do with Sheets in Apps Script.
Remove Duplicate Rows - A good small tutorial that will teach you the basics of Sheets and Ranges and how to manipulate them.
To export all my WooCommerce orders on a scheduled basis, I used a ready-made solution.
I used a WooCommerce API and JSON client. It worked smoothly: I got the WooCommerce API, and the JSON client was implemented in the tool already.
You just need to choose endpoint in the JSON client to get the required data. I exported all orders once a month, so I used the base URL http:// mydomain /wp-json/wc/v3/orders and my endpoint was orders.
You can check this article to understand better how it works for your purpose.
And here is WooCommerce API documentation.
I assume that setting up an export through the Apps Script is more flexible (and based on the answer above, it's working indeed), but I'm not a code guy. So I searched for an easier solution, and the API + JSON client helped.
Hope you'll find it helpful.
I would like to suggest using WooCommerce Google Sheet Plugin
I am trying to do a query and cannot seem to crack the syntax of this. So I need to grab surveys for the current month, most recent, limit it to 5, and then order by the count of the related table which is the responses for the survey. So if a survey has had 8 responses and another 4, the one with 8 will show up at the top.
I have a scope set to find surveys for the month, but either I need to ditch that for a more involved query, or find a way to order it by the max survey.response_count .
This is the closest I have gotten but is still not correct.
#sorted_active_surveys = Survey.joins(:survey_responses).group(:survey_id).order('COUNT(survey_responses.survey_id) DESC')
If I try in combination with the scope the created_at date becomes ambiguous and errors out.
Survey.rb
scope :for_month, ->(date) { where("MONTH(created_at) = ?", date.month).limit(5) }
This also creates the same error
scope :for_month, ->(date) { where("MONTH(survey.created_at) = ?", date.month).limit(5) }
Any help would be GREATLY appreciated.
This doesn't keep the scope but seems to order by response count correctly and keep the dates within the current month.
Survey.where('surveys.created_at > ? AND surveys.created_at < ?', Time.now.beginning_of_month, Time.now.end_of_month).joins(:survey_responses).group(:survey_id).order('COUNT(survey_responses.survey_id) DESC')
GAS novice here, but enjoying it.
Here is a data sample in a Google Sheet called "Sheet1".
I have a Google Script that formats this data, creates a new sheet called "totals by account" that sets "A1" to the formula: =QUERY(Sheet1!A:J,'select E, sum(J) group by E',0)"
This all works well, but the cell/Query gives a "Forumla parse error" message. I've seen this Query work before, but it doesn't seem to be consistent. I formatted column J to a number and "0.00" (DATA_SHEET.getRange("J1:J1000").setNumberFormat("0.00");)
Thank you for your help!
Try replacing quotes with double quotes in the query :
=QUERY(Sheet1!A:J,"select E, sum(J) group by E",0)
I want to change the order of my list when display using facetWP.
I have attached the image so that you could understand what i require.
Here is the query
$sql = "SELECT f.facet_value, f.facet_display_value, f.term_id, f.parent_id, f.depth, 0 AS counter FROM {$wpdb->prefix}facetwp_index f WHERE f.facet_name = '{$facet['name']}' AND post_id IN ($raw_post_ids) GROUP BY f.facet_value ORDER BY $orderby LIMIT $limit";
Thanks in advance.
Please see the last example on this page: https://facetwp.com/documentation/facetwp_facet_orderby/
Since this is a custom database table (not wp_posts), you will need to modify the SQL query itself, via the aforementioned filter.
I'm trying to do build an automatic report query with the Google Analytics spreadsheet add-on. I want to get a monthly report (start of month to end of month) about users, visits etc. According to the Google Analytics documentation, it's possible to set a startDate and endDate in the following format:
Values must match [0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo).
However i'm getting an error which looks like this:
Report failed
My settings looks like this:
Settings in Google Spreadsheet
Does anybody know what causes my error? This feature will be really handy.
Thanks in advance.
First you have to schedule your report every month and then you can use the function eomonth() to calculate start and end dates.
Start date -> = EOMONTH(TODAY(),-2) +1
End date -> = EOMONTH(TODAY(),-1)
Try running it on a different profile or a larger date range. I was able to get data using the exact query that you shared. You can also try the Google Analytics Query Explorerand see if that gives you works or it gives you more detailed error information.