In column A there is a list of tasks.
In column B each task has an associated group.
How to, using built-in formulas, generate sequence like in column D?
Here is a screenshot :
try:
=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(QUERY(IF(A2:B="",,A2:B&"♦"),
"select max(Col1) where Col1 is not null group by Col1 pivot Col2", 0)
,,999^99)),,999^99), "♦"))))
This should work as well as player0s. I keep trying to get him to use FLATTEN() :)
=QUERY(FLATTEN(TRANSPOSE(QUERY(A2:B,"select Max(A) group by A pivot B"))),"where Col1<>''")
Related
My table has data similar to the following:
Raw Data
I am flattening the data into two columns using the following:
=INDEX(QUERY(SPLIT(FLATTEN(IF(SheetName!B1:D=TRUE, SheetName!B1:D1&"×"&SheetName!A1:A,)), "×"),"where Col2 is not null order by Col1 asc"))
The result is depicted here:
Flattened Data
However, I also need to return within the "flattened data" columns the following:
1#email.com | 1#email.com
2#email.com | 2#email.com
3#email.com | 3#email.com
In other words, I need to return SheetName!A1:A&"×"&SheetName!A1:A for each email address contained in the email column (Column A), in addition to the other data that is being flattened into the column. I have tried variations using IF/IFS statements, wildcards (not permitted within IFs), etc. However, I am now seeking some help after striking out many times. Thanks for any help you can offer!
Update Example spreadsheet with sample data and current vs. desired results (formula in cell H2):
https://docs.google.com/spreadsheets/d/1wq9kR4UqYeWsqSCbnkGGHbR-TIHTfaBb_ixGk41X2cs/edit?usp=sharing
perhaps:
=INDEX(QUERY(SPLIT(FLATTEN(IF(SheetName!B1:D=TRUE,
SheetName!B1:D1&"×"&SheetName!A1:A&"×"&SheetName!A1:A,)), "×"),
"where Col3 is not null order by Col1 asc"))
update:
=INDEX({QUERY(SPLIT(FLATTEN(
IF(Sheet1!B1:F=TRUE, Sheet1!B1:F1&"×"&Sheet1!A1:A,)), "×"),
"where Col2 is not null order by Col1");
TEXT(UNIQUE(FILTER(A2:A, A2:A<>"")), {"#", "#"})})
I have created a Google Sheet query that is pulling data from four other sources.
=QUERY({'1ST A'!A4:BF;'1ST B'!A4:BF;'1ST C'!A4:BF;'1ST D'!A4:BF},"select * where Col1 <>''")
It works well. I am trying to add an additional query that enables the data to be sorted in the master spreadsheet according to a value in the specific column. I am trying to add something like this...
=query(A4:BF,"select * order by N asc")
How do I combine the two criteria and am I writing the command correctly?
try:
=QUERY({'1ST A'!A4:BF; '1ST B'!A4:BF; '1ST C'!A4:BF; '1ST D'!A4:BF},
"where Col1 <>'' order by Col14 asc")
I'm trying to get a pivot table, where I can select the values from something like a slicer.
I found out that using GETPIVOTDATA can get the trick with a dropdown list, but not very usefull since it's only 1 cell.
try:
=QUERY({A2:A8, INDIRECT(
ADDRESS(2, MATCH(D10, 1:1, 0))&":"&
ADDRESS(8, MATCH(D10, 1:1, 0)))},
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label sum(Col2)''", 0)
I am working on an SQL query which should group by a column bidBroker and return all the columns in the table.
I tried it using the following query
select Product,
Term,
BidBroker,
BidVolume,
BidCP,
Bid,
Offer,
OfferCP,
OfferVolume,
OfferBroker,
ProductID,
TermID
from canadiancrudes
group by BidBroker
The above query threw me an error as follows
Column 'canadiancrudes.Product' is invalid in the select list because it is not contained in either an aggregate function or the
GROUP BY clause.
Is there any other way which returns all the data grouping by bidBroker without changing the order of data coming from CanadadianCrudes?
First if you are going to agregate, you should learn about agregate functions.
Then grouping becomes much more obvious.
I think you should explain what you are trying to accomplish here, because I suspect that you are trying to SORT bu Bidbroker, rather than grouping.
If you mean you want to sort by BidBroker, you can use:
SELECT Product,Term,BidBroker,BidVolume,BidCP,Bid,Offer,OfferCP,OfferVolume,OfferBroker,ProductID,TermID
FROM canadiancrudes
ORDER BY BidBroker
If you want to GROUP BY, and give example-data you can use:
SELECT c1.Product,c1.Term,c1.BidBroker,c1.BidVolume,c1.BidCP,c1.Bid,c1.Offer,c1.OfferCP,c1.OfferVolume,c1.OfferBroker,c1.ProductID,c1.TermID
FROM canadiancrudes c1
WHERE c1.YOURPRIMARYKEY IN (
select MIN(c2.YOURPRIMARYKEY) from canadiancrudes c2 group by c2.BidBroker
)
Replace YOURPRIMARYKEY with your column with your row-unique id.
As others have said, don't use "group by" if you don't want to aggregate something. If you do want to aggregate by one column but include others as well, consider researching "partition."
Aim:
Count (column 3) and sum(values of column 4) based on a unique combination of column 1 and column 2;
Is this possible in one SQL statement? If yes, what is the precise syntax?
Explanation: Consider a table with 4 columns like
The task is to count all Id_Indiv and to sum up the weight values depending on the 4 existing unique combination of genus & species.
The desired output is
If possible to create the desired output in one sql statement, it could read somewhat like:
SELECT genus, species, count(ID_Indiv) as NoOfIndiv, sum(weight)
FROM (
SELECT DISTINCT
genus,
species
FROM TableName
)W
group by genus, species;
Note: there might be more than 50 possible Genus*species combinations, and we do not know if/when new combinations will come up. Thus I cannot predefine the combination, but the statement has to identfy them.
Please, could somebody help me with the exact Sql statement?
Thanks a lot in advance!
What do you use nested SELECT statement? You don't have to do that!
SELECT genus, species, count(ID_Indiv) as NoOfIndiv, sum(weight)
FROM TableName
GROUP BY genus, species;
GROUP BY will take care of making {genus, species} pair unique within each group.
It seems like your attempt was very close... so I'm not sure if I'm oversimplifying the issue... but shouldn't just a simple GROUP BY do what you are looking for?
SELECT
genus,
species,
COUNT(*) AS NoOfIndiv,
SUM(weight) as TotalWeight
FROM YourTable
GROUP BY
genus,
species