Friday, August 9, 2013

Google Spreadsheet Advanced Pivot Table Query

Question:

( by Lakedawgs )


 feel like I over complicated my request below.
I am basically trying to see if it is possible to automatically break out the income and expense totals by month on the 'Total Budget' page in the attached spread sheet. 

Sheet "Expenses":


Sheet "Income":


This may be a lot harder than I realize, not sure,
Thanks much

Solution:

Have a look at the following screenshot:



I have the following formula in Cell A1:

=query(Arrayformula(iferror(if({1,0,0};choose(month('Income'!B5:B);"01 Jan";"02 Feb";"03 Mar";"04 Apr";"05 May";"06 Jun";"07 Jul";"08 Aug";"09 Sep";"10 Oct";"11 Nov";"12 Dec");'Income'!B5:D)));"select Col3,sum(Col2) where Col1<>'' group by Col3 pivot Col1 label Col3 'Inflows', sum(Col2) '' ")

I have the following formula in Cell A15:

=query(Arrayformula(iferror(if({1,0,0};choose(month('Expenses'!A5:A);"01 Jan";"02 Feb";"03 Mar";"04 Apr";"05 May";"06 Jun";"07 Jul";"08 Aug";"09 Sep";"10 Oct";"11 Nov";"12 Dec");if({0,1,0};'Expenses'!E5:E;'Expenses'!B5:B))));"select Col3,sum(Col2) where Col1<>'' group by Col3 pivot Col1 label Col3 'Outflows', sum(Col2) '' ")


I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.


I also take up private and confidential projects:
If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: http://igoogledrive.blogspot.com/2012/09/donate.html 

Thanks,

3 comments:

  1. Seems a nice solution to a common problem. But there are few points I wasn't able to understand: For Incomes Table: How that IF statement works with {1,0,0} ? When that if statement is true it gives Months instead of full date but how the rest of Incomes table added after?

    Also, how come query has 2 sum(Col2) statements, isn't just 1 enough?


    ReplyDelete
  2. I kind of started to understand. By giving an array of values in curly brackets and putting whole formula in Arrayfunction you get like a matrix output.
    However I replicated those tables you provided as example and used formula you provided above, I didn't end up with same result. It gives error. Is there a working example shared?

    ReplyDelete