Sum up values in excel based on multiple conditions - excel-formula

I have an excel worksheet which captures hours spent by resources for tasks for each work day. The input sheet looks like this -
I need to pull a report based on this data to gather number of hours filled by each resource on each day between a date range (specified by a start and end date). Sample output looks like this -
I have tried using SUMIFS but it fails to give me an output as the row/column range for all conditions and the sum range needs to stay same, which is not same for my case.
Can someone suggest an alternative to get required data?

SUMIF will work for you but you need a dynamic sum range.
This bit can help you achieve that:
=SUMIF($A$2:$A$9,$A15,INDIRECT(CHAR(64+MATCH(B$14,$A$1:$G$1,0))&"2:"&CHAR(64+MATCH(B$14,$A$1:$G$1,0))&"8"))
Most important part is CHAR(64+MATCH(B$14,$A$1:$G$1,0)) which searches position of your date and converts it into column name.
I used 2 and 8 as indicator for the beginning and end of sum range and wrapped everything with INDIRECT to convert string to cell reference.

Related

Calculate Percentage of results equaling a value within a date range

I'm attempting to write a formula that will show a completion % from multiple columns within a date range on a sheet. I have it working if I put the exact cell range in the formula like this: =COUNTIF(Jason!B2:K31,"COMPLETE")/COUNTA(Jason!B2:K31) Specifically I'm looking for the number of tasks marked complete in all cells over a month and showing a %.
Results
This will be a running document updated daily so I want to be able to use a formula that will filter the results by month.
Daily Log
I have tried using =COUNTIF(FILTER(Jason!B2:K31,(Jason!A2:A31>=Performance!B3)*(Jason!A2:A31<Performance!B4),"None"),"COMPLETE") but apparently you can't use FILTER that way.
Any help is greatly appreciated.
Use Two SUMPRODUCTS
=SUMPRODUCT((Jason!B2:K31="COMPLETE")*(Jason!A2:A31>=Performance!B3)*(Jason!A2:A31<Performance!B4))/SUMPRODUCT((Jason!B2:K31<>"")*(Jason!A2:A31>=Performance!B3)*(Jason!A2:A31<Performance!B4))
We can use LET to get rid of some of the duplicates:
=LET(r,Jason!B2:K31,
ld,Performance!B3,
hd,Performance!B4,
d,Jason!A2:A31,
arr,(d>=ld)*(d<hd),
SUMPRODUCT((r="COMPLETE")*arr)/SUMPRODUCT((r<>"")*arr)

How to automatically change reference based on variable in excel

So I'm trying to create a Forecast using historic data from 2 years. Each year's data is broken down into weeks and weeks that haven't occurred yet are set to 0. I'm struggling trying to create a formula that will automatically run a Forecast on only the weeks in the year that have occurred. I created this formula which Excel won't execute:
=UNIQUE(FILTER(WkSht!G:(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))
I'm trying to use VLOOKUP to replace the second part of a cell reference based off a lookup table. So if F1 is 25, for example, then the Filter function will be:
=UNIQUE(FILTER(WkSht!G:AE,(WkSht!A:A)=(B1))
That second formula works on its own as intended, but I'm trying to create this excel file so that it requires minimal work to update in the future and manually changing the range seems like a bit too much work to expect other people to do.
So I guess my question is:
How do I change part of the reference automatically?
Maybe I could do:
=UNIQUE(FILTER(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))
And have to lookup values contain the reference text?
Alternatively, is there a way to filter out the last of the 0's in the FORECAST.ETS function (as some values might intentionally be 0s in earlier weeks)?
To get a variable width range, you can use the construct
SomeRange:INDEX(MaxRange,,NumberOfColumns)
In your case SomeRange would be
WkSht!G:G
MaxRange would be something like
WkSht!G:Z
where you replace Z with a column that comfortably covers all your (future) data
NumberOfColumns is your VLookup (You probably want an exact match?, If so include the 4th parameter =0)
Demo:
=UNIQUE(FILTER(WkSht!G:G:INDEX(WkSht!G:Z,,VLOOKUP(F1,DH2:DI54,2,0)),WkSht!A:A=B1))
Sample data on sheet WkSht

Using a date range in an array formula

I've got a data-set, for example purposes it's a list of people (who may appear more than once) with various fields.
I need to return every match and I've done this with an array formula.
My data looks like this from Column A to F with the look up result shown in Column F. (I've simplified it for sample purposes):
and the data updates perfectly when i update the name in cell F1
This is my formula
{=IFERROR(INDEX($C$2:$C$27, SMALL(IF(COUNTIF(F$1,$A$2:$A$27), ROW($C$2:$C$27)-1,""), ROW()-1)),"")}
However I need to also to include the date in the criteria, specifically I want to be able to provide a date range, and then only return matches that are within that date range.
I've found many examples of having multiple matches in the criteria (using more than 1 countif and multiplying the results together) but nothing that will allow me to specify a date range.
I don't want to use VBA for this, hoping someone out there can assist.
always the case.
After posting that query, I managed to work it out myself.
I just changed my formula to :
{=IFERROR(INDEX($C$2:$C$27, SMALL(IF(COUNTIF(F$1,$A$2:$A$27)*($G$1>=$B$2:$B$27), ROW($C$2:$C$27)-1,""), ROW()-1)),"")}
(where G1 had a date in it) i also added a <= statement in there as well to give it a start and end date
sorry for wasting the time of anyone who looked into this for me

excel Sum every other column up to certain month

I have a Simple spreadsheet with 2 rows:
ActualJAN | BudgetJAN | ActualFEB | BudgetFEB | ActualMAR | BudgetMAR ....
100 200 300 400 500 600 ....
I'd like to sum ONLY the Budget columns up to the current month (Month(Today()).
Same for the Actual columns.
So if we're currently in February,
Budget to date would be: 600=200+400
Actual to date would be: 400=100+300
I just can't seem to get there, at least simply and elegantly.
This is a non array formula that performs array like operations. As such large range references should be avoided or you will experience a slow down or potential crash of your system. For a small defined range works great so long as the formula is not repeated too many times either.
Additionally TODAY() is a volitile function which means the formula will recalculate whenever anything in the spreadsheet changes, not just when something related to the formula changes.
This formula is generalized a bit so your data can be located anywhere on your sheet and does not require rearrangement of your data.
To get your actual sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="A"))
To get your Budget sum use the following:
=SUMPRODUCT($C$4:$H$4*(COLUMN($C$4:$H$4)-COLUMN($C$4)+1<=MONTH(TODAY())*2)*(LEFT($C$3:$H$3)="B"))
Change C4:H4 to suit your number range. ChangeC3:H3 to suit your column title range. Change C4 to be the first cell of your number range.
Caveat: Assumes maximum 12 months starting at January
Proof of concept:
I would recommend structuring your data differently. It would be an easier task if you arrayed everything vertically and divided your data into three columns. The first would be Category, which would be populated with either "Budget" or "Actual." The next column would be Month. After that, of course, you have the Value column. Then, use a basic SUMIF, like "=SUMIF(A1:A6,"Budget",C1:C6)." A1:A6 is the range Excel will scan for the desired variable. In this case, that variable is "Budget." Then, C1:C6 is the value that corresponds to a "Budget" month. That formula will give you the answer you want as long as you expand the SUMIF formula to include the full range of values, e.g., "SUMIF(A1:A317,"Budget",C1:C317)."
So I think I understand what you're trying to do, I cannot make the entire formula without the rest of the spreadsheet but this is working currently:
For the Actual:
=IF(MONTH(TODAY())=1,A2,IF(MONTH(TODAY())=2,A2+C2,IF(MONTH(TODAY())=3,A2+C2+E2,"")))
For the Budget:
=IF(MONTH(TODAY())=1,B2,IF(MONTH(TODAY())=2,B2+D2,IF(MONTH(TODAY())=3,B2+D2+F2,"")))
Here is the spreadsheet I created to test:
If you give me the rest of the data I can complete the formula, basically all you would need to do is add more months to the formula and change the amounts it adds.
I am sure there is probably a more efficient way to accomplish this but this way works.
I suggest a hidden row to control your dates. Say, January is in column C, enter [C1] =1, [D1] =C1, [E1] =C1+1, [F1] =E1. Select E1:F1 and copy to the right until December. Hide row 1.
In row 2 use these two formulas.
[C2] ="Actual" & UPPER(TEXT("1/" & C$1,"mmm"))
[D2] ="Budget" & UPPER(TEXT("1/" & D$1,"mmm"))
Select C2:D2 and copy to the right until December. This exercise isn't required because the resulting display is exactly what you already have. But producing this result with the help of formulas ensures freedom from error, and it is faster. As an added bonus you get a visual check of what's in the hidden row.
Now you can use this formula to extract totals from row 3 where you have your values.
=SUMIFS($C3:$Z3,$C$2:$Z$2,"Budget*",$C$1:$Z$1,"<="&MONTH(TODAY()))
Change "Budget" to "Actual" and the same formula will extract the actual amounts.

Sum the number of days in one date range which fall within a second date range

I have two columns of dates. One is the move in date and the other the move out date. I want to figure out how many days the tenant was there during a second date range. for example: how many total "bed days" did we have in the month of July? 7/1/2016-7/31/2016
This function calculates the number of days each tenant was there each month but I would like it if I could get the entire calculation into one cell without creating a dummy column for each month.
=MAX(0,MIN(EOMONTH($B$2,0),I14)-MAX($B$2,H14))
I tried to change a few things and use it as an array function but it is not working. I am very new to array functions so I may be doing it completely wrong.
=SUM(MAX(0,MIN(EOMONTH($B$2,0),I:I)-MAX($B$2,H:H)))
any help is much appreciated! Let me know if you need more info too.
Bad news - you can't use MAX and MIN in an array formula like this because instead of treating H and I as two arrays it just treats them as one big long array and you only get one value out of them.
You also need to add 1 to your original formula because if they moved in on the last day of the month (say) it should still count as one day.
If you replace the MAX and MIN with IF statements you get something like this
=SUM(IF(IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)<0,0,
IF(EOMONTH($B$2,0)<IF(I2:I10="Active",TODAY(),I2:I10),EOMONTH($B$2,0),IF(I2:I10="Active",TODAY(),I2:I10))-IF($B$2>H2:H10,$B$2,H2:H10)+1))
which has to be entered using CtrlShiftEnter
A useful tip if you are new to arrays is not to include more rows in an array formula than you need to because it will be slow, and test it first on a small number of rows so that you can step through it using Evaluate Formula if you run into trouble.

Resources