Calculating rows that match a month in the header - google-sheets

I'm trying to calculate the monthly totals for fruit that I record sales of weekly.
I have a table that records the above data.
I would like another table that calculates the SUM values for each month for that fruit. Because every month has a potentially different number of weeks, I need a formula to essentially cycle through the weeks for the particular fruit I'm interested in and SUM the values for that month dynamically.
I've tried a bunch of different things, like:
=IF(A3:A5="Banana", SUM(INDEX(C2:J2,,MATCH("January",C3:F3))))
...in the hopes that I could somehow:
Search for a fruit in a table
If found, run through the weeks and
calculate monthly values
Spreadsheet here

In B9 try this formula
=sum(filter(filter($C$3:$5, month($C$2:$2)=column()-1), $A$3:$A$5=$A9))
Fill down and to the right as far as needed.

Related

Sum in ARRAYFORMULA based on possible cell values of two rows, then subtract another sum based on two different date values in two different columns

I really couldn't put the title into words very well. I will link a template spreadsheet below.
I've been working on a formula for hours now however I keep hitting dead ends. I'm unable to effectively do what I believe should be feasible. I'd give my attempts however I believe it would be of zero help, instead I'll explain my desired outcome.
I have a page with my employees, the E column isn't populated right now as I'd like to create a formula (ARRAYFORMULA so I don't have to paste a formula into each cell) to calculate the output based on a few conditions and values.
Vacation days are calculated as follows. The CEO gets 5, managers get 3 and assistants get 1. Extra vacation days based on points employees receive, 30 points or above is 5, 20 points or above is 3 and 10 or above point is 1.
Calculating the amount of vacation days employees have earned wasn't the hard part for me, it was having the formula subtract days based on how many vacation days have been used in the past 30 days.
We log vacations on the vacation page. The formula on the employees page needs to calculate how many vacation days each employee has used in the past 30 days only and subtract that from the total earned vacation days that employee has earned.
I'd like for the formula to use TODAY() to calculate 30 days in the past however for the sake of this example I'll use the date 06/09/2021 instead for continuity.
Sorry if I haven't explained this well or I'm asking too much in one go, I figured all the context is required.
Example sheet

Creating Google Sheets pivot tables with custom formula

I am creating table for finance: will have a data base of trades: date open and close for trade (), open and close prices, ticket is a stock name, change is percentage which is calculated base on open-close price and days are also calculated base on two dates as on the picture:
And I need to generate a new table for each month of the year (in which I have date records). So, Google sheets has Pivot tables and that what I need. I need columns: average win % per month, average loss % per month, average number of win days per month, average number of loss days per month.
I did that in 2 separate tables:
First table:
First table settings:
Second table:
Second table settings:
But I can not create that in one table - I do not know how to make custom formula. So, I am looking for some help here.
I tried some things, I can filter, make average. But I do not know how to get array of items with sorted pivot table data by months...If I can get sorted pivot table data by months - I can filter by positive/negative and find average.
My sample: https://docs.google.com/spreadsheets/d/1TCLWZ7-oUSwM8DLODPpH6wwssgfYyo3BVlEpWj78kV4/edit?usp=sharing

Find Number of Days in Current Month That Fall Between Date Range In Google Sheets

I'm trying to come up with a function that will calculate a monthly budget from within a specified date range. I tried to use SUMIFS but I can't figure out how to isolate a specific month within the range.
Example:
We have a sheet with Google Ad campaigns, with a row for each campaign.
We are running one Google Ad campaign (A) from 2/15/20 to 5/15/20 with a total budget of $3000 from which I calculate a daily budget of $33.33.
We are running a second campaign (B) from 5/15/20 to 8/15/20, also with a budget of $3,000, from which I calculate a daily budget of $32.61.
=IF(NOT(ISBLANK(Start_Date)),Total_Budget/(End_Date-Start_Date),"")
In a separate sheet, I have Budget and Spend fields for each month. For May, I need it to calculate the total budget for 5/1-5/15 of Campaign A, and 5/15-5/31 of Campaign B.
I got this far (J is the Daily_Budget, G is the Start_Date, and H is the End_Date):
=SUMIFS(Google!J2:J30, Google!G2:G30,"<="&DATE(2020,5,1),Google!H2:H30,">="&DATE(2020,5,31))
Then I was at a loss for how to extrapolate the number of days from the range, so that I could then multiply them by the Daily Budget and then add them together.
I thought of going back to the sheet that contains the campaigns and adding columns for each month with a complicated conditional, and then just using SUM(), but I feel like there has to be a more elegant solution.
UPDATE
Per request, here is a link to the spreadsheet with the desired results manually entered: Click here. May & June show the campaign partial month overlaps. The result I'm ultimately going for is =(15*Google!J2)+(16*Google!J3).
UPDATE 2 (24Jun20)
Per request, I have shared the spreadsheet so that people can make a copy and experiment with formulas: Click here..
Any ideas?
Thanks,
Ty
I would use the function DATEDIF() (documentation here). You can set the first parameter as the first day of the month you are trying to calculate the number of days within it, and the second as the first day from another month. Example:
DATEDIF(DATE(2020, 1, 1), DATE(2020, 2, 1), "D")
You could probably make a custom function with this as well to input only the number of each month (and year, in case of leap years on February), but I don't have much experience with that unfortunately.

Sum every nth cell in a row infinitely

I am making a spreadsheet for my football (or soccer) team, and tracking how much each player has paid and whether they're in credit/debt so I'm calculating the balance in Sheet1 per game and then in Sheet2 calculating the total balance.
The formula I am trying to do is, in Sheet2 trying to SUM each value under the "Balance" column for (every 3 cells) for Aidan together to get the total balance.
At the moment I am just doing the following but need it to accommodate an infinite amount of columns (fixtures) and be scalable because currently, this is not.
=SUM(Sheet1!D3, Sheet1!G3)
Any help would be massively appreciated.
you can use FILTER of MOD in SUM like:
=SUM(FILTER(B2:2, MOD(COLUMN(B2:2)+2, 3)=0))
Since the goal is to sum all values from columns with header "Balance", you could also do this:
=sumproduct(Sheet1!$B$2:$J$2="Balance",Sheet1!B3:J3)
That way you don't have to worry about the index of those columns, should you ever decide to add more columns to your sheet.

SUMIF/SUMPRODUCT match multiple criteria within date range

I have a table (Sales) data that has two sets of columns with code, amounts and date reference:
And I have another table (Sheet1):
which need to sum the total net amount with one set subtract the other set on the Sales table but it have to matched the code and based on the weekly date range in Sheet1 table. I can sum the total amount together but I can't separate it with date.
Try:
=SUMIFS(Sales!I:I,Sales!F:F,$A4,Sales!G:G,$C4,Sales!H:H,">="&Sheet1!D$1,Sales!H:H,"<="&Sheet1!D$2)
IF you want the difference between the sum of the blues and the sum of the reds subject to the same conditions, repeat the above (with adjustments to suit) at the beginning and link the two together with a -.
I've work this one out. This is my formula:
=SUMPRODUCT(--(Sales!$C$1:$C$1000>=$C$1),--(Sales!$C$1:$C$1000<=$C$2),--(Sales!$A$1:$A$1000=A4),Sales!$D$1:$D$1000)-SUMPRODUCT(--(Sales!$H$1:$H$1000>=$C$1),--(Sales!$H$1:$H$1000<=$C$2),--(Sales!$A$1:$A$1000=A4),Sales!$I$1:$I$1000)

Resources