I have this table
Col1 | Col2 | Col3
1 MeYou | You | Them
2 Them | They | You
3 Them | Me | They
4 They | Us | We
5 Us | Them | MeAsk
I would like to do these Query
Select all rows from MyTable
Where Col1 contains 'Me' or Col2 contains 'Me' or Col3 contains 'Me'
Select all rows from MyTable
Where (Col1 contains 'Me' or Col3 contains 'Me') and Col2 equals to 'Them'
Based on the table shown and using the condition that I wanted on my query, Query 1 should get 3 rows in return.
The returned rows must be row1, row3 and row5. Query 2 should get only 1 row in return and that is row5.
My question is how am I going to compose this kind of query in CAML query for my sharepoint apps?
Thanks in advance :)
First Query
<Where>
<Or>
<Contains>
<FieldRef Name='Col1' />
<Value Type='User'>22</Value>
</Contains>
<Or>
<Contains>
<FieldRef Name='Col2' />
<Value Type='User'>22</Value>
</Contains>
<Contains>
<FieldRef Name='Col3' />
<Value Type='User'>22</Value>
</Contains>
</Or>
</Or>
</Where>
second Query
<Where>
<Or>
<Contains>
<FieldRef Name="Col1" />
<Value Type="User">22</Value>
</Contains>
<And>
<Contains>
<FieldRef Name="Col2" />
<Value Type="User">23</Value>
</Contains>
<Contains>
<FieldRef Name="Col3" />
<Value Type="User">22</Value>
</Contains>
</And>
</Or>
</Where>
Related
I have this table:
Name | Age
Ann | adult
Ann | adult
Andrew | adult
Mike | adult
Ann | teenager
John | teenager
John | teenager
I want this output:
Age | count Name (distinct Names)
adult | 3
teenager | 2
Unfortunately, I can't go further then this formula:
=QUERY(table; "select B, count(A) group by B"; 1)
where the 'table' is the named range with input data. And it gives me this:
Age | count Name
adult | 4
teenager | 3
I need something like:
=QUERY(table; "select B, count(unique(A)) group by A"; 1)
which obviously doesn't work.
So, how can I achieve my target output with querying?
I know, I can do that with pivot tables with countunique function, but I want to go without pivot tables.
One option could be QUERY + UNIQUE:
=QUERY(UNIQUE(A2:B),"SELECT Col2, COUNT(Col1) WHERE Col2 IS NOT NULL GROUP BY Col2")
You can also make use of this formula:
=ARRAYFORMULA(QUERY(UNIQUE({B:B, B:B & A:A, A:A}), "SELECT Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)'count Name'", 1))
After
Explanation
The formula makes use of the following functions:
ARRAYFORMULA
UNIQUE
QUERY
In order to find the unique values, the UNIQUE is used for the range needed for the query (A:B) such that the sorting and counting is done on this range. The LABEL is used as well in order to set the header name for the resulted column.
Reference
ARRAYFORMULA;
UNIQUE;
QUERY.
I am importing XML data to a google sheet which has the following structure:
edit: URL: https://sonicstate.com/news/tools/revive_stats/client_camp_3785.xml
<data>
<campaignId>15802</campaignId>
<campaignName>Some name</campaignName>
<startDate>
<year>2021</year>
<month>12</month>
<day>02</day>
</startDate>
<endDate>
<year>2021</year>
<month>12</month>
<day>13</day>
</endDate>
</data>
<data>
.... another record
</data>
I want the results of multiple rows to be imported with date values concatenated so they can appear in manageable rows in the sheet I can then query while the other values will appear in their own cells with a row for each record.
eg
15802 | Some name | 2021/12/02 | 2021/12/13
15803 | Another name | 2021/11/30 | 2021/12/04
I have tried:
IMPORTXML("myurl" , "//data/campaignId | //data/campaignName | //data/startDate/year | //data/startDate/month|//data/startDate/day")
But each value returns on a separate row with cells for year, month, day
eg:
15802
Some Name
Year | Month | Day
15802
Another Name
Year | Month | Day
etc
I also tried:
IMPORTXML("myurl" , "concat(//data/campaignId , //data/campaignName , //data/startDate/year,'/', //data/startDate/month,'/',//data/startDate/day")
But that only returns a single record. I'm struggling to find the right terms to search for what I am trying to achieve. Also Sheets XMLIMPORT uses XPath 1.0 which limits the functions available
try:
=INDEX(SUBSTITUTE(TRIM(SPLIT(FLATTEN(SPLIT(QUERY(FLATTEN(QUERY(TRANSPOSE(
IFERROR(IF(0=MOD(ROW(A:A)-1, 5)-{0, 1, 4, 3, 2}, {"♦","","","",""}&TEXT(
IMPORTXML(A1, "//data/campaignId|//data/campaignName|//data/startDate/year|//data/startDate/month|//data/startDate/day"),
{"#","#","#","#","#"})&{"♠","♠","","♣","♣"}, ))),,9^9)),,9^9), "♦")), "♠")), "♣ ", "/"))
formula explanation
shorter fx:
=INDEX(SUBSTITUTE(TRIM(SPLIT(FLATTEN(SPLIT(QUERY(IFNA(
CHOOSE(MATCH(MOD(SEQUENCE(999)-1, 5), {0, 1}), "♦", )&
IMPORTXML(A1, "//data/campaignId|//data/campaignName|//data/startDate/year|//data/startDate/month|//data/startDate/day")&
CHOOSE(MATCH(MOD(SEQUENCE(999)-1, 5), {0, 1, 2, 3, 4}), "♠","♠","♣","♣","")),,9^9), "♦")), "♠")), "♣ ", "/"))
Try this
in A1 : your url
in A2 : your function without any change
in B1 : put 5 as you request 5 values per item
in B2 :
=ARRAYFORMULA(VLOOKUP(SEQUENCE(ROUNDUP(COUNTA(A2:A)/B1),B1,ROW(A2)),{ROW(A2:A),A2:A},2,0))
https://docs.google.com/spreadsheets/d/1nFcPgXgRc11-WWICG8Y8KEsB4qAoOt1lIbptHzXdC4M/edit?usp=sharing
try:
=INDEX({IMPORTXML(A1, "//data/campaignId"),
IMPORTXML(A1, "//data/campaignName"),
IMPORTXML(A1, "//data/startDate/day")&"/"&
IMPORTXML(A1, "//data/startDate/month")&"/"&
IMPORTXML(A1, "//data/startDate/year")})
I've got data like:
06/16/2021 14:35:06 | 10
06/16/2021 15:42:57 | 2
06/16/2021 18:00:48 | 3
06/16/2021 19:11:28 | 7
06/16/2021 20:33:57 | 15
06/17/2021 8:10:40 | 15
06/17/2021 9:17:06 | 14
06/17/2021 10:25:47 | 14
06/17/2021 11:35:05 | 14
And want to display a chart that has totals for each day. To collect the days I've got
=UNIQUE(ARRAYFORMULA(TO_DATE(INT(FILTER(A1:A, A1:A<>"")))))
and I've been able to build up a couple SUMIFs with a single hard-coded value:
=SUMIF(ARRAYFORMULA(EQ(TO_DATE(INT(A1:A)),$K$2)),TRUE(),B1:B)
=SUMIF(ARRAYFORMULA(EQ(TO_DATE(INT(A1:A)),$K$3)),TRUE(),B1:B)
(where K2:K will be the unique dates from the formula above)
I'm just missing the final component - removing the hardcoded K column values and auto-populating it (with an ARRAYFORMULA or QUERY). Any tips?
I believe this should be possible with a single query. See if something like this helps?
=ArrayFormula(query({int(A:A), B:B}, "Select Col1, sum(Col2) where Col1 > 0 group by Col1 label sum(Col2)'' format Col1 'mm/dd/yyyy'", 0))
I have data in google sheet I just want to fetch that data in my other sheet but in transpose
Here is ex:
Column A | Column B | Column C
=================================
site1.com | Name 1 | Name 2
site2.com | Name 3 | Name 4
site3.com | Name 5 | Name 6
Want to data like this
Column A | Column B | Column C
=================================
site1.com | site2.com | site3.com
Name 1 | Name 3 | Name 5
Name 2 | Name 4 | Name 6
I don't want to enter formula manually in every row so is arryformula can do this automatic.
I'm trying this but not able to what I want.
=ARRAYFORMULA(TRANSPOSE(Sheet1!$B2:B300 & Sheet1!$L2:L300))
try:
=ARRAYFORMULA({TRANSPOSE(SORT(FILTER(A:A, A:A<>"")));
SUBSTITUTE(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(QUERY(QUERY({A:B; A:A, C:C},
"select count(Col1) where Col1 is not null group by Col1 pivot Col2"),
"offset 1", 0)), SUBSTITUTE(QUERY(QUERY({A:B; A:A, C:C},
"select count(Col1) where Col1 is not null group by Col1 pivot Col2"),
"limit 0"), " ", "♦"), )),,999^99)), " ")), "♦" , " ")})
or you can do just:
=TRANSPOSE(A1:C3)
or:
=TRANSPOSE(INDIRECT("A1:C"&COUNTA(A:A)))
UPDATE:
=QUERY(TRANSPOSE(INDIRECT("Sheet1!A2:L"&COUNTA(Sheet1!A2:A)+1)), "offset 1")
What would be a good approach to calculate the number of occurrences in a spreadsheet column? Can this be done with a single array formula?
Example (column A is input, columns B and C are to be auto-generated):
| A | B | C |
+-------+-------+-------+
| Name | Name | Count |
+-------+-------+-------+
| Joe | Joe | 2 |
| Lisa | Lisa | 3 |
| Jenny | Jenny | 2 |
| Lisa | | |
| Lisa | | |
| Joe | | |
| Jenny | | |
A simpler approach to this
At the beginning of column B, type
=UNIQUE(A:A)
Then in column C, use
=COUNTIF(A:A, B1)
and copy them in all row column C.
Edit: If that doesn't work for you, try using semicolon instead of comma:
=COUNTIF(A:A; B1)
Try:
=ArrayFormula(QUERY(A:A&{"",""};"select Col1, count(Col2) where Col1 != '' group by Col1 label count(Col2) 'Count'";1))
22/07/2014 Some time in the last month, Sheets has started supporting more flexible concatenation of arrays, using an embedded array. So the solution may be shortened slightly to:
=QUERY({A:A,A:A},"select Col1, count(Col2) where Col1 != '' group by Col1 label count(Col2) 'Count'",1)
=COUNTIF(A:A;"lisa")
You can replace the criteria with cell references from Column B
Just adding some extra sorting if needed
=QUERY(A2:A,"select A, count(A) where A is not null group by A order by count(A) DESC label A 'Name', count(A) 'Count'",-1)
=arrayformula(if(isblank(B2:B),iferror(1/0),mmult(sign(B2:B=TRANSPOSE(A2:A)),A2:A)))
I got this from a good tutorial - can't remember the title - probably about using MMult
Put the following in B3 (credit to #Alexander-Ivanov for the countif condition):
={UNIQUE(A3:A),ARRAYFORMULA(COUNTIF(UNIQUE(A3:A),"=" & UNIQUE(A3:A)))}
Benefits: It only requires editing 1 cell, it includes the name filtered by uniqueness, and it is concise.
Downside: it runs the unique function 3x
To use the unique function only once, split it into 2 cells:
B3: =UNIQUE(A3:A)
C3: =ARRAYFORMULA(COUNTIF(B3:B,"=" & B3:B))