How do you sort a range reference (more than one column) using the Excel C API in ExcelDNA XlCall.Excel(xlcSort, ... ) and passing in a column reference to sort by?
In the documentation, it says the syntax is SORT(orientation, key1, order1, key2, order2, key3, order3, header, custom, case) but it doesn't have any mention to the actual range to sort.
Are you able to sort using multi column range using C API?
Govert van Drimmelen, author of ExcelDNA project, answered this for me over on his project's Google groups forum.
https://groups.google.com/d/msg/exceldna/h3SqSA8DkPc/Avbi-0IgBQAJ
Related
I'm having difficulty summing two separate ranges based on a condition -- essentially a SUMIF of data from a remote sheet.
Currently, I'm using a formula that combines both ranges. This works, but will become problematic when I attempt to SUM ranges that are not vertically aligned.
Formula I'm using now (which works):
=SUM(QUERY(IMPORTRANGE($B$34,TEXT($B2,"m/d/yyyy")&"!$F$8:$I$19"),"SELECT Col4 where Col1='"&$C$34&"'",0))
Formula Key:
- $B$34 = Reference to Google Spreadsheet
- $B2 = Reference to Sheet Name
- $C$34 = Reference to Condition
I'd like to split up the combined range ($F$8:$I$19) into two separate ranges ($F$8:$I$12 + $F$15:$I$19). I've made several unsuccessful attempts, including this one:
=SUM(QUERY(IMPORTRANGE($B$34,TEXT($B2,"m/d/yyyy")&"!$F$8:$I$12"),"SELECT Col4 where Col1='"&$C$34&"'",0))+SUM(QUERY(IMPORTRANGE($B$34,TEXT($B2,"m/d/yyyy")&"!$F$15:$I$19"),"SELECT Col4 where Col1='"&$C$34&"'",0))
Guidance would be very much appreciated.
You can view the test sheets I'm using here:
Formula Test:
https://docs.google.com/spreadsheets/d/1x6blsRLlfYXvTlO_cf71woY6yC4K2HxjKyMKZnvbUI8/edit#gid=1027872696
Target Data:
https://docs.google.com/spreadsheets/d/1tZBhtoZWcE-BKdwNy0cQ4H4_ktGVpDHVG2rarZlr4I4/edit#gid=0
This approach seems to work:
=SUM(QUERY({IMPORTRANGE($B$34,TEXT($B2,"m/d/yyyy")&"!$F$8:$I$12");IMPORTRANGE($B$34,TEXT($B2,"m/d/yyyy")&"!$F$15:$I$19")},"SELECT Col4 where Col1='"&$C$34&"'",0))
Hat tip: Google Sheets - QUERY from Another Sheet, IMPORTRANGE, Use Multiple Tabs, Subquery Examples Tutorial
Is it possible to create a "List from a range" Data Validation rule in Google Sheets where the range skips columns?
For example:
Cells A6:A11 is limited to the range A1:B3. Cells B6:B11 is limited to the range A1:A3 AND C1:C3 (skips column B).
Creating a Data Validation rule for cells A6:A11 is trivial as I simply need to create a Criteria of "List from a range = A1:B3".
However, creating the Data Validation rule for cells B6:B11 is not so intuitive since Google Sheets does not allow me to create a Criteria using the syntax "List from a range = A1:A3, C1:C3".
Does the "List from a range" Criteria support a syntax that allows us to skip columns within a range?
Note: I currently have a work around for this where I defined an array formula in D1 = =ArrayFormula(if({1,""},A1:A3,C1:C3)) and then use D1:E3 as the Data Validation range. But this is a hacky solution and I'm hoping there is a better way to accomplish my goal.
The solution is to use { } to create a combination of columns or rows that will result in some sort of virtual table on-the-fly.
Example:
Assuming you have a spreadsheet with Name, Age, Gender, Phone and Address in A, B, C, D and E, and you want to skip the Gender (column C) while using the UNIQUE statement, you can use something like this.
Put in G1 the following formula:
=UNIQUE({A1:B, D1:E})
From the cell G1, the spreadsheet will populate the columns G, H, I and J with unique combinations of A, B, D and E, excluding the column C (Gender).
The same application of a combined range can be used in any formula and also you can combine multiple different ranges, including cross Spreadsheets and Files.
It is a very useful trick if you need to combine pieces of multiple spreadsheets for data visualization or reports. However, always remember you cannot manipulate the displayed data. You can still search through it, format it, etc., but you cannot change it. On the other hand, it will auto-update always if the data source gets updated, which is very useful.
Note: Try it with LOOKUP, VLOOPUP or HLOOKUP.
I am interesting in doing a range scan on columns for a particular row key. So far, using Twitter's cassandra client, it was straight forward to figure out a range scan for int based columns:
db.get(:cf, rk, {:start => 1, :finish => 10})
I cannot for the life of me however, find documentation on DataStax's site on how to do start/finish scans based on other data types, even for text/utf8.
I ran into a blog post where the poster was using the tilde "~" in order to note the end of an ASCII range scan. Is there an official page on DataStax's website that documents the different range scans one can perform on columns based on their datatypes?
Cassandra stores all data in a row sorted based on the comparator that you defined for the column family. The most accurate information about the comparator types will be found directly in the source tree. Each type has a corresponding class in the db/marshal directory. If you look at the UTF8Type.java class you can see it implements a compare method that (eventually) does a byte by byte comparison.
So for an ascii encoding you will get an ascii sort where:
"A" < "AA" < "a" < "aa"
In Google spreadsheet I want to query data in another sheet but the problem is that the name of sheet is present in a cell. So is there a way in QUERY function to dynamically mention sheet name. Basically I am trying to do something like this but with dynamic sheet name:
=QUERY('2012'!A2:F;"select C, sum(F) where A='December' group by C order by sum(F) desc")
I tried to do this but I get Parse Error:
=QUERY(INDIRECT("Overview!L5")!A2:F;"select C, sum(F) where A='December' group by C order by sum(F) desc")
In which Overview!L5 is the cell with sheet name to query. I also tried to concatenate quotes around INDIRECT but that didnt work either.
I think it is quite evident what I am trying to do from the query i.e. get sum of values in cells grouped by values in other cells.
the INDIRECT looks to be the problem.
Try like this:
=query(INDIRECT(A1&"!A5:A10"),"select Col1")
i.e. if Cell A1 contains "food" the above is the same as:
=query(food!A5:A10,"select A")
and the same as:
=query(INDIRECT("food!A5:A10"),"select *")
**Note: the indirect uses "Col1" etc and not "A" because it does not pass the col letters.
Also ... The google groups forum might be a good place to look for spreadsheet formula answers. productforums.google.com/forum/#!categories/docs/spreadsheets
Easiest way to use dynamic structures in a query is to not include functions inside query but prepare strings in separate cells, for instance A1 for address B1 for arguments and then just QUERY(A1;B1)
I'm using ImportXML in a Google Spreadsheet to access the user_timeline method in the Twitter API. I'd like to extract the created_at and text fields from the response and create a two-column display of the results.
Currently I'm doing this by calling the API twice, with
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at")
in the cell at the top of one column, and
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/text")
in another.
Is there a way for me to create this display with a single call?
ImportXML supports using the xpath | separator to include as many queries as you like.
=ImportXML("http://url"; "//#author | //#catalogid| //#publisherid")
However it does not expand the results into multiple columns. You get a single column of repeating triplets (or however many attributes you've selected) as shown below in column A.
The following is deprecated
2015.06.16: continue is not available in "the new Google Sheets" (see: The Google Documentation for continue).
However you don't need to use the automatically inserted CONTINUE() function to place your results.
=CONTINUE($A$2, (ROW()-ROW($A$2)+1)*$A$1-B$1, 1)
Placed in B2 that should cleanly fill down and right to give you sane column data.
ImportXML is in A2.
A3 and below are how the CONTINUE() functions are automatically filled in.
A1 is the number of attributes.
B1:D1 are the attribute index for their columns.
Another way to convert the rows of =CONTINUE() into columns is to use transpose():
=transpose(importxml("http://url","//a | //b | //c"))
Just concatenate your queries with "|"
=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at | /statuses/status/text")
I posed this question to the Google Support Forum and this is was a solution that worked for me:
=ArrayFormula(QUERY(QUERY(IFERROR(IF({1,1,0},IF({1,0,0},INT((ROW(A:A)-1)/2),MOD(ROW(A:A)-1,2)),IMPORTXML("http://example.com","//td/a | //td/a/#href"))),"select min(Col3) where Col3 <> '' group by Col1 pivot Col2",0),"offset 1",0))
Replace the contents of IMPORTXML with your data and query and see if that works for you. I
Apparently, this attempts to invoke the IMPORTXML function only once. It's a solution for now, at least.
Here's the full thread.
This is the best solution (NOT MINE) posted in the comments below. To be honest, I'm not sure how it works. Perhaps #Pandora, the original poster, could provide an explanation.
=ArrayFormula(iferror(hlookup(1,{1;ARRAY},(row(A:A)+1)*2-transpose(sort(row(A1:A2)+0,1,0)))))
This is a very ugly solution and doesn't even explain how it works. At least I couldn't get it to work due to multiple errors, like i.e. to much parameters for IF (because an array is used). A shorter solution can be found here =ArrayFormula(iferror(hlookup(1,{1;ARRAY},(row(A:A)+1)*2-transpose(sort(row(A1:A2)+0,1,0))))) "ARRAY" can be replaced with IMPORTXML-Function. This function can be used for as much XPATHS one wants. – Pandora Mar 7 '19 at 15:51
In particular, it would be good to know how to modify the formula to accommodate more columns.