Using Query command to extract, compare and list data - spreadsheet

I run a music festival and the data given by the ticketing provider is extremely poorly laid out, in a spreadsheet format with vertical merges. From this data, We use google Sheets to extract camping tickets from other festival ticket types and then allocate camping tent numbers. The proposed solution is:
1: Extract camping tickets using Query commmand:
=QUERY(TicketData!A1:S50000, "Select C,D,E, F, G,N, S where I contains 'Season Shared Camping - 10 man tent'Order By C").
But the Query command must also:
2: compare results with a static sheet of existing allocations
3: Only display entries that are not also in static existing allocations sheet.
Thus the Query command now shows only new, unallocated camping ticket purchases which need to be actioned. Once placed in the static sheet, the entry will be automatically removed from the query sheet as it now exists in both sheets.
Unique Identifier is column C, and the column which contains the text string which identifies if it is a camping ticket is column S.
Thank you

I imagine you have that downvote due to this not being an excel question, but it being tagged as so. Either way I think I have a solution.
Writing complicated requirements into a query string can sometimes be quite tough as it usually requires escaping the string and weaving in cell references etc. What you can do is do part of the work in the 'data' section of the Query formula and then use the query string to select just the columns you want.
I've done this by using =FILTER and COUNTIF:
Step 1: Filter the TicketData using the 'Season Shared...' string and the Static values with:
=FILTER(TicketData!A:S, TicketData!I:I = "Season Shared Camping - 10 man tent", COUNTIF(TicketData!C:C, Static!C:C) > 0)
Step 2: Tie this into the Query, substituting the above Filter for the data section of the Query. We need to refer to columns as Col1, Col2 etc so it will look like this:
=QUERY(FILTER(TicketData!A:S, TicketData!I:I = "Season Shared Camping - 10 man tent", COUNTIF(TicketData!C:C, Static!C:C) > 0), "select Col3, Col4, Col5, Col6, Col7, Col14, Col19")
I tried this on some mock data and it worked for me. Let me know how you get on.
Edit: After looking at the data in the comment it looks like my Filter needs some altering as the Static list is a different length to the other filter data. I got round this by concatenating all the static IDs together (comma separated) and then using the FIND formula. If it doesn't find anything it is picked up by the ISERR formula and comes through in the filter:
=QUERY(FILTER(TicketData!A:S, TicketData!I:I = $C$2, ISERR(FIND(TicketData!C:C, CONCATENATE(TRANSPOSE(Shared!A:A&","))))), "select Col3, Col4, Col5, Col6, Col7, Col19")
You can see this working on the public data you provided by clicking here.

Related

Google Sheets - Is it possible to use query to search for the data from the sheets that i select with dropdown list? If not, what can i do?

GoodDay everyone, recently I am trying to learn about using the Google Sheets. My question is same as the title, and these are some examples of the data.
The data from first sheet
The data from second sheet
I am trying to create a searching function in the main page in order to get some data by selecting a specific sheet.
And these are the result I expect to see.
By choosing option using the dropdown list, I expect the query or any other things will detect the option and display all the data I need from the sheet I have chosen.
RESULT EXPECTED 1
RESULT EXPECTED 2
RESULT EXPECTED 3
Is that even possible in Google Sheets?
use:
=INDEX(QUERY({
IFERROR(JACKIE!A4:A/0, "JACKIE"), JACKIE!A4:B;
IFERROR(KELVIN!A4:A/0, "KELVIN"), KELVIN!A4:B},
"where Col2 is not null
and Col1 = '"&B2&"'
and Col3 = '"&B3&"'", ))

Combine Rows but concatenate on a certain field in Excel Power Query or Microsoft SQL

I have brought a table from an Authority database into Excel via power query OBDC type, that includes fields like:
Date - various
Comments - mem_txt
Sequence - seq_num
The Comments field has a length restriction, and if a longer string is entered, it returns multiple rows with the Comments field being chopped into suitable lengths and the order returned in the Sequence field as per extract below. All other parts of the records are the same.
I want to collapse the rows based and concatenate the various Comments into a single entry. There is a date/time column just outside of the screen shot above that can be used to group the rows by (it is the same for the set of rows, but unique across the data set).
For example:
I did try bring the data in by a query connection, using the GROUP_CONCAT(Comments SEPARATOR ', ') and GROUP BY date, but that command isn't available in Microsoft Query.
Assuming the date/time column you refer to is named date_time, the M code would be:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
#"Grouped Rows" = Table.Group(
Source,
{"date_time"},
{{"NewCol", each Text.Combine([mem_text])}}
)
in
#"Grouped Rows"
Amend the Source line as required.

How to use a google sheets pivot query to output strings

I have a (much larger) table like this sample:
I am trying to output a table that looks like this:
The closest I can get with a pivot query returns numerical results in the value fields, rather than the desired text strings
=query(Data, "Select D,count(D) group by D Pivot B")
I resorted to a series of formulas to build my row and column headers, and then fill in the data field - See Version 3 in the sample sheet. But I couldn't figure out how to fill in the data with a single formula - as opposed to copying and pasting in the data field, which is not desirable with a dynamic number of row and column headers based on the original data.
Is there a way to wrap my data field formula (in cell B44 of the sample) in an arrayformula that will fill the data field, with a dynamic number of columns and rows?
Or even more advanced is there a formula that will deliver my desired results table in a single formula?
This should work, it's a bit difficult to explain, but i could demonstrate the various parts if you opened up your sheet to editable...
=ARRAYFORMULA(TRANSPOSE(QUERY(TRIM(SPLIT(TRANSPOSE(QUERY(QUERY({CHAR(10)&A2:A11,B2:B11&"|"&D2:D11&"|"},"select MAX(Col1) group by Col1 pivot Col2"),,9^9)),"|",0,0)),"select Col1,MAX(Col3) where Col1<>'' group by Col1 pivot Col2 order by Col1 desc label Col1'Project'")))

Retrieving Columns with count greater than 1 - Google Sheet Query

I'm using Google sheets, and I want to get the data from one sheet to another where I want only the columns with count > 1.
Let's say we have 3 columns A, B, and C. I tried the following (the first sheet name is "Form Responses 1"):
I thought about using a query in the second sheet as: =query('Form Responses 1'!A1:Z, "Select A having count (A) >1 union select B having count (B) >1 union select C having count (C) > 1"). But I got a parse error where it seems that union and having are not supported in google sheets query.
How can I achieve this (whether it's using query or any other Google sheets function that can work)?
More details:
The first sheet contains info about exercises conducted during a lecture and it gets its data from a Google Form (so the responses are fed in this sheet). Here is a screenshot of it:
Please note that the form is divided into sections. When the user selects the course, the attendance, the participation, and adds a comment, then they go to the next section, the next section will be based on the selected course, the newly opened section will have the exercise name and rating questions (the exercise name is a dropdown list with items that are prefilled and specific to the selected course). That's why, you can see that "exercise name" and "rate the exercise" columns are repeated because we have 2 sections in this form.
The second sheet should contain the data of a selected course only (either mobile dev or web dev) which can be achieved easily through a query with a where clause. But, in addition to that, it shouldn't contain the empty columns of "exercise name" and "rate the exercise" as they correspond to another section. So, it should have only one exercise name column and one rating column that correspond to the selected course. Here is a screenshot if we only use a query with where clause without removing the extra name and rating columns:
Here is a screenshot with the desired result:
Thanks.
why not use just:
=QUERY('Form Responses 1'!A1:Z, "select A,B,C,D,E,F,G where F is not null", 1)
Use "OR" condition
Eg:-
QUERY(Data!A:R,"select A, N, P where N>0 or P>0")
where A column has country and N, P columns have population values

Measure occurrences in MS Access SQL

I was wondering whether it is possible (and if it is, the way) to perform the following task in Microsoft Access: there are two tables; first one consists of three columns 1) ID 2) tweet text and 3) date. Second table is a single vector of words, like a lexicon. For every row of the first table, I want to measure occurrences of the words of the second table (lexicon) in the tweet text column (2). Following, I want to add a new column in the first table, in which I will keep a record of these occurrences. My ultimate purpose is to perform some sort of sentiment analysis.
In case this helps, this is what I have done so far:
SELECT *
FROM Tweet_data
WHERE Tweet_text LIKE "*" & Positive_sentiment & "*";
However, I most probably have to make some changes in the part following the LIKE
If you think there is a more practical way to perform such task (sentiment analysis) I am open to suggestions.
You can use like in a join:
SELECT *
FROM Tweet_data td LEFT JOIN
Lexicon l
ON td.Tweet_text LIKE "*" & l.Positive_sentiment & "*";
The part of your question on how to do sentiment analysis is too broad for Stack Overflow. I will say, though, that MS Access is not the first tool that comes to mind.
EDIT:
The question is your comment is quite different from your actual question, but it is really a simple variation:
SELECT l.Positive_sentiment, count(td.tweet_text) as cnt
FROM Lexicon l LEFT JOIN
Tweet_data td
ON td.Tweet_text LIKE "*" & l.Positive_sentiment & "*";