Find matching month between datasets and sequence a multiplication between values in specific rows between the sets - excel

I have a sheet for a Project P&L with a data sequenced using the following formula where C2 is 01/01/2020 and E2 is the duration of the project at 39 months:
=EDATE($C$2, SEQUENCE(1, $E$2, 0))
This gives the following:
I have another sheet called Studio Costs which has a calculated per person monthly expense as follows:
For the Project P&L sheet I'd like to create a sequenced formula in I9 for Project Costs based on the number of months determined by E2(39), such that it compares the date in row 1 with the dates in row 1 of the dataset in the Studio Costs sheet, and on finding the matching column, multiply the Monthly Per Employee Costs value in row 5 by the Active Staff value in row 2 of the Project P&L dataset to give the monthly studio costs.

Formula to be placed in I9:
=(I2:P2)*HLOOKUP(I1:P1,'Studio Costs'!$AC$1:$AL$5,5,FALSE)
Change ranges as needed.
EDIT: Final solution to use dynamic ranges author came up with:
=(I2:INDIRECT(ADDRESS(ROW(I2),COLUMN(I2)+$E$2-1)))*HLOOKUP(I1:INDIRECT(ADDRESS(ROW(I1),COLUMN(I1)+$E$2-1)),'Studio Costs'!$B$1:$KO$5,5,FALSE)

Related

How to create a dynamic formula to find the average of a set of values for a given vector

I am trying to create a formula that gives me the average of the last 12 entries in a given dataset depending on the associated vector.
Let's make an example:
I have in column F2,G2,H2 and I2 dates, Company1, Company2 and Company3 respectively. Then from row3 to row 33 I have months dates starting from May 2016.
Date Company1 Company2 Company3
May-16 2,453,845
Jun-16 13,099,823
Jul-16 14,159,037
Aug-16 38,589,050 8,866,101
Sep-16 63,290,285 13,242,522
Oct-16 94,005,364 14,841,793
Nov-16 123,774,792 7,903,600 41,489,883
Dec-16 93,355,037 12,449,604 69,117,105
Jan-17 47,869,982 13,830,712 83,913,764
Feb-17 77,109,905 10,361,555 68,176,643
The goal is to create a formula that, when I drag it down, correctly calculates the average of the last 12 values for a given company.
So for example i would have, say in table "B2:C5":
Company1 76,856,345
Company2 11,120,859
Company3 65,674,349
And, if a new Company4 is added to the list, then I just have to drag it down the formula, to calculate the average of the last 12 months for Company4.
Until now, I have came up with this formula:
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(G:G),ROW(G:G)),ROW(INDIRECT("1:"&MIN(12,COUNT(G:G))))),ROW(G:G),G:G ))
This formula correctly calculates the average of a given column, considering only the last 12 values. The last step would be to come up with a formula that includes all the columns and then calculates the average for the given company.
Thanks!
I recommend that you use a named range to define your data in columns G:I. When a company is added, just modify the named range's specs. I used the name Target. Of course, you can replace it with $G:$I if you feel so inclined but I would rather recommend reducing the number of rows in the range, which is easier to manage when it is named.
Use the formula below to extract the company names from the first row of Target into the first column of your averages table. This is to ensure that the names are spelled identically in both locations.
=INDEX(Target,1,ROW()-2)
The number 2 indicates the number of rows above the row containing the formula. it is copied here from cell M3. There, ROW()-2 creates the number 1, counting sequentially as the formula is copied down.
Now I have the formula below in my cell N3 and copied down.
=SUM(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))
The formula simply sums up the columns G, H, and I in 3 consecutive rows.
In the final step I inserted the range definition established above, meaning excluding the SUM() function, into your existing formula.
=AVERAGE(LOOKUP(LARGE(IF(ISNUMBER(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0)))),ROW(INDIRECT("1:"&MIN(12,COUNT(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))))),ROW(INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))),INDEX(Target,0,MATCH($M3,INDEX(Target,1,0),0))))

Use dynamic sum range and criteria range in SUMIFS

I'm using SUMIFS to calculate sales revenue of product X over a period of time. The problem is that all the sum range and the criteria ranges are dynamic since sales reps will add more rows to record new sales everyday. My formula looks like this:
=SUMIFS(Revenue!I5:I24,Revenue!F5:F24,"Product X",Revenue!B5:B24,">="&B3,Revenue!B5:B24,"<="&C3)
The starting row is row 5, and the last row that currently has data is row 24.
Revenue is the worksheet that contains the data. In this worksheet, column I is the revenue, column F is the product name, column B is the date that the revenue is recorded. B3 and C3 are the start and end date of the period.
When a sales rep records a new revenue, the last row that has data will become row 25, so my formula won't count it in. I tried to replaced 24 with 1000 hoping that it would count when new data was added beneath, but it returned #VALUE.
What should I do?
Thank you
Declare 3 dynamic ranges and use their names in your formula.
=IFERROR(SUMIFS(revenueI,revenueF,"Product X",revenueB,">="&B3,revenueB,"<="&C3),"")
Adding the names: Press Ctrl+F3 to open the name manager and then enter the 3 names
Name: revenueB
RefersTo=
OFFSET(Revenue!$B$5,0,0,COUNTA(Revenue!$B$5:$B$1048576),1)
Name: revenueF
RefersTo=
=OFFSET(Revenue!$F$5,0,0,COUNTA(Revenue!$F$5:$F$1048576),1)
Name: revenueI
RefersTo=
=OFFSET(Revenue!$I$5,0,0,COUNTA(Revenue!$I$5:$I$1048576),1)
1048576 is for the max number of rows in more recent versions of Excel. Adjust to the total number of rows for your Excel version.
Wrap in an IFERROR in case of errors e.g. if named ranges are off different length.

SumIF three conditions meet return the forth column value

I am having two sheets Sheet1 & Sheet2, Sheet1 having four columns like EMP No, Project Number, Month & Working Days.
In the sheet2 I have same four column but some employee will be worked in two projects for that month, For example: If Emp No, project number & month matches, then 4th column value for that employee should be populated. And I am doing this by referring the cells in both the sheets.
Both sheets having the same order as mentioned in the below.
Column A = Emp No,
Column B = Project Number
Column C = Month
Column D = Working Days
=SUMIFS('Sheet2',$D$2:$D$10000,$C$2:$C$10000,"="&M2,$B$2:$B$10000,"="&C2,$A$2:$A$10000,A2)
I gather your aggregation happens in Sheet2 so the formula should be:
=SUMIFS(Sheet1!D:D,Sheet1!A:A,Sheet2!A1,Sheet1!B:B,Sheet2!B1,Sheet1!C:C,Sheet2!C1)
If your aggregations happens in Sheet1 just go with this one:
=SUMIFS(Sheet2!D:D,Sheet2!A:A,Sheet1!A1,Sheet2!B:B,Sheet1!B1,Sheet2!C:C,Sheet1!C1)
If I've understood correctly, Sheet2 can contain multiple lines for employees per project per month? So, for example, EMP No 1 could be listed for Project 1, in the month of January 5 times, with working days each time equalling 1, and Project 2, int he month of January 2 times, with working days each time equalling 1.
Your Sheet1 worksheet, intends to list all employees, projects and months uniquely in order to total the days worked on each project each month? Based on the example, EMP No 1 would have the following displayed:
What I would suggest, is providing you have the unique list in Sheet1 already set up, enter the following formula into cell D2 (Working Days) and then copy down. I have assumed 100 entries on Sheet2, so you will need to amend the Sheet2! ranges in the formula to suit your data.
=SUMIFS(Sheet2!$D$2:$D$101,Sheet2!$A$2:$A$101,Sheet1!$A2,Sheet2!$B$2:$B$101,Sheet1!$B2,Sheet2!$C$2:$C$101,Sheet1!$C2)

Excel Complex Conditional

Ok so I did this in LibreOffice but now I have to duplicate it to excel for my Pay Roll department since they use excel. So I am having to figure out how to convert the formulas to Excel. This is only 1 of two totaling formulas that did not convert when I saved it as Excel format.
I have the following sheet called DailyReport
I am currently calculating Column M with =SUMPRODUCT(A2:A200=A2, G2:G200)
Then on a secondary sheet I have the following second sheet WeeklyReport
Now what I want to do is if WeeklyReport Column A2 == DailyReport Column A then take the date in DailyReport Column B and test it to fall in the date range in WeeklyReport Column B and Column C with =IF(AND(DailyReport.B2>=B2,DailyReport.B2<=C2),1, 0) and if that is true add the Total Daily Hours to the total in WeeklyReports Column D from DailyReports Column M
I hope this is clear enough if not please let me know what else I can do to make my question more clear.
Thanks in advance!
So, to me it sounds like:
You want a sum of all hours, for a specific employee (defined by the A column value weekly report), in between the dates specified (also defined by weekly report, b & c column) - and you want the end result to be in WeeklyReport column D and all of it to relate to the same row as the result?
sumproduct will do the trick. I am renaming your sheets to DR and WR for my sanity's sake.
=sumproduct((DR!G$2:G$200)*(DR!A$2:A$200=A2)*(DR!B$2:B$200>=B2)*(DR!B$2:B$200<C2))
Now, if you want a new daily report sheet every day it gets a bit trickier to do with formulas alone, you should then have a macro to store the "current" value and add the "new" value, or for simplicity's sake create more columns (one for each working day) and duplicate the formula to all daily columns, or have as many named dailyreports as there are working days in a week and increase the formula to check multiple sheets. I would add columns - least amount of work and the dumbest solution often proves the most resilient.
Did that help in any way?

Excel: Trailing 3 month decline using data from a pivot table

(http://stackoverflow.com/questions/5283466/calculate-moving-average-in-excel seems to be somewhat related. I'm curious to know the non-vba way to do this.)
My my pivot table has source data that creates a count of how many sales a person had in the past 36 days. Each day os 1 column in the pivot table, and the persons name is on the row.
Some of these people did not have sales on day1, day2, etc, and may only have 3 days where they sold something on days 14,15 and 16. No matter what their sequence, I want to to find the most recent sale data (closest to the right edge of pivot table) and calculate three sales increases e.g. C20/C19 will be >1 if they had more sales on the whatever day C20 is. The increase ca nbe fond by subtracting 1 and changing to percent. The problem is, if a person only had sales on d10, d11, d12 then how can I put a general formula in Excel to say "look for the most recent consecutive sales, then calculate this ratio"? For a person who had sales in the past three days, that's easy. It will be chaotic to hardcode where to look for each sales value.
d1 d2 d3 d4...d7 d8 d9...d34 d35 d36 mostrecentincrease nextrecent
ant 1 5 7 7/5=1.4 5/1=5
bat ...10 11 12... 12/11=1.blah 11/10=1.1
cat 2 6 9 13
dog 19 20 20/19=1.blah 19/blank=0
elf 4 4/dnexist=0
i don't have excel here, but i hope this will guide you to the correct result (use , instead of ; if that is your list separator):
define sales as a range of values from d1 to d36 for a given row (or use actual ranges)
compute positions of the last values for each row using these array formulas (use ctrl+shift+enter instead of just enter after you write these formulas):
position_1 =max(if(sales<>0;column(sales)))
position_2 =max(if((sales<>0)*(column(sales)<>position_1);column(sales)))
position_3 =max(if((sales<>0)*(column(sales)<>position_1)*(column(sales)<>position_2);column(sales)))
retrieve the values:
value_1 =index(sales;position_1)
do some error handling (=iferror(...;0)) and the like...

Resources