Search code examples
google-sheetsgoogle-sheets-formulaformula

How can I separate a column into multiple columns based on values?


I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.

Data Screenshot

I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this

enter image description here

I'm okay with the start of the formula

=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")

But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.

Do you have a solution for what I'm trying to do? Thank you in advance :)


Solution

  • try:

    =INDEX({
     QUERY({MONTH(A2:A), B2:C}, 
     "select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"), 
     QUERY({MONTH(A2:A), B2:C, C2:C}, 
     "select count(Col3) where Col2 is not null group by Col1 pivot Col4")})
    

    enter image description here